Hi Ronny,

Ok, now I get what's going on. Forms make a lot of permission checks before being rendered. One of this checks must be failing, and thus the page is blank: http://hobocentral.net/manual/faq/blank-form

I have reproduced the problem in Hobo 2.0 and RailsSettings. When the form tried to render, I can see in the log:

  permission denied; unable to render form

Looking into the source code and using the "better_errors" gem to debug, I've been able to trace it to the method "attribute_protected?" (lib/hobo/model/permissions.rb). I've found out that while rendering a edit Setting form, this is returning true when it should return false.

As a workaround, in the model I have added an empty string to attr_accessible:

  attr_accessible :var, :value, :thing_id, :thing_type, :''

This works with Hobo 2.0, but I suspect it's not going to help you with Hobo 1.3, as I believe the attribute whitelisting is different with Rails 3.0. It it doesn't work, you can try to debug the problem using better_errors or a debugger. Alternatively, if you send me the app through email I can try to find what's going on :).

Regards,
Ignacio

El 21/05/13 04:18, Ronny Hanssen escribió:
Hi Ignacio,

The edit-page is rendered, but it seems that it doesn't accept any of
the fields as being editable, hence does not show them at all. I have
tried setting the update_permitted?, and even the edit_permitted? and
<field>_edit_permitted? variants
(http://cookbook-1.3.hobocentral.net/manual/permissions#defining_edit_permission).
However, since even the "edit"-link is missing I assume that Hobo
somehow finds these records to be uneditable as a whole.

There are a couple of things in the RailsSettings solution that I find
very handy, caching and scope for getting values as well as defaults
(both persisted and memory) on startup. Since this is basically a
standard ActiveRecord with a few class-methods I would have thought that
it would work fine. This is the major file in that gem:
https://github.com/huacnlee/rails-settings-cached/blob/master/lib/rails-settings/settings.rb

I was hoping that there were a small change that I just needed to do to
make it work. Otherwise I guess I will have to write the input-fields
myself, without any checks for editability, and override when saved to
ignore the Hobo-permissions. Also, I wanted to use the opportunity to
understand more of how the permission system in Hobo works - under the hood.


On Monday, May 20, 2013 11:43:39 PM UTC+2, Ignacio Huerta wrote:

    Hi Ronny,

    What do you mean with "I am not able to make the model editable"? Does
    the form appear? It it does, what happens after you submit it? What
    does
    the log say?

    On the other hand, I've never used RailsSettings, so I don't know
    how it
    works. When I need to save application settings, I usually create a
    model called "options", with two fields "key" and "value" (hobo g
    resource option key:string value:string). Then I can do:

        Options.find_by_key("whatever")

    And I have the standard Hobo CRUD interface in /options.

    Regards,
    Ignacio

    El 20/05/13 19:53, Ronny Hanssen escribi�:
     > Hi all,
     >
     > Long time since I had any time to do Hobo related work. Nice to
    see how
     > this moves on. I am on Hobo 1.3, but I am hoping to move to 2.0
    in not
     > too long.
     >
     > I am changing a current 1.3 app where I want to make some
    application
     > settings available. To do this I am trying to use
     > the RailsSettings::CachedSettings project
     > (https://github.com/huacnlee/rails-settings-cached
    <https://github.com/huacnlee/rails-settings-cached>). It kinda works
    very
     > well.
     >
     > *The problem appears when I try to setup a user interface for
    changing
     > the settings. I can list the index page, I can show the fields,
    but I am
     > not able to make the model editable, no matter what i try. Anyone
    have a
     > clue on why?*
     >
     > Inspecting the generated form shows this:
     >
     >     <def tag="form" for="Setting">
     >        <form merge param="default">
     >          <error-messages param/>
     >          <field-list fields="" param/>
     >          <div param="actions">
     >            <submit label="#{ht 'setting.actions.save',
     >     :default=>['Save']}" param/><or-cancel param="cancel"/>
     >          </div>
     >        </form>
     >     </def>
     >
     >
     > Other than that, the edit-page looks like this:
     >
     >     <def tag="edit-page" for="Setting">
     >        <page merge title="#{ht 'setting.edit.title',
    :default=>['Edit
     >     Setting'], :name => name(:no_wrapper => true) }">
     >          <body: class="edit-page setting" param/>
     >          <content:>
     >            <section param="content-header">
     >              <h2 param="heading">
     >                <ht key="setting.edit.heading"
    name="#{name(:no_wrapper
     >     => true)}">
     >                  Edit Setting
     >                </ht>
     >              </h2>
     >              <delete-button label="#{ht 'setting.actions.delete',
     >     :default=>['Remove This Setting']}" param/>
     >            </section>
     >            <section param="content-body">
     >              <form param/>
     >            </section>
     >          </content:>
     >        </page>
     >     </def>
     >
     >
     > The controller is quite standard for a subsite controller.
     >
     >     class Admin::SettingsController < Admin::AdminSiteController
     >        hobo_model_controller
     >        auto_actions :all, :except => [:new, :create, :destroy]
     >     end
     >
     >
     > The model looks like this:
     >
     >     class Setting < RailsSettings::CachedSettings
     >        hobo_model # Don't put anything above this
     >        fields do
     >          var :string, :null => false, :name => true
     >          value :text, :primary_content => true
     >          thing_id :integer
     >          thing_type :string, :limit => 30
     >          timestamps
     >        end
     >        never_show :thing_id, :thing_type
     >        # --- Permissions --- #
     >        def create_permitted?
     >          false
     >        end
     >        def update_permitted?
     >          acting_user.administrator?
     >        end
     >        def destroy_permitted?
     >          false
     >        end
     >        def view_permitted?(field)
     >          true
     >        end
     >     end
     >
     >
     >
     >
     > --
     > You received this message because you are subscribed to the Google
     > Groups "Hobo Users" group.
     > To unsubscribe from this group and stop receiving emails from it,
    send
     > an email to [email protected] <javascript:>.
     > To post to this group, send email to [email protected]
    <javascript:>.
     > Visit this group at
    http://groups.google.com/group/hobousers?hl=en
    <http://groups.google.com/group/hobousers?hl=en>.
     > For more options, visit https://groups.google.com/groups/opt_out
    <https://groups.google.com/groups/opt_out>.
     >
     >

    --
    Ignacio Huerta Arteche
    http://www.ihuerta.net
    Tel�fono: 0034 645 70 77 35
    Email realizado con software libre

--
You received this message because you are subscribed to the Google
Groups "Hobo Users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



--
Ignacio Huerta Arteche
http://www.ihuerta.net
Teléfono: 0034 645 70 77 35
Email realizado con software libre

--
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to