On Aug 31, 5:29 am, kevinpfromnm <[email protected]> wrote:
> Your permission code might be helpful for this.
Here is the code of the model for the child record:
class Observation < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
number enum_string(:"0", :"1 to 5", :"5 to 20", :"20 to
50", :"50 to 100", :"100+" )
comment :string
timestamps
end
belongs_to :survey, :accessible => true
belongs_to :frog
validates_presence_of :frog
has_one :site, :through => :survey
def name
frog.to_s
end
set_search_columns :comment
# --- Permissions --- #
def create_permitted?
acting_user == self.survey.contact or acting_user.administrator?
end
def update_permitted?
acting_user == self.survey.contact or acting_user.administrator?
end
def destroy_permitted?
acting_user == self.survey.contact or acting_user.administrator?
end
def view_permitted?(field)
p field
p number
true
end
end
The view_permission? code is just some debugging code to show what is
going on. When I view the child records from a parent record the
output is:
:"0"
#<Observation id: nil, number: nil, comment: nil, created_at: nil,
updated_at: nil, survey_id: nil, frog_id: nil>
:survey
#<Observation id: 537, number: "1 to 5", comment: nil, created_at:
"2010-06-05 22:33:31", updated_at: "2010-06-05 22:33:41", survey_id:
612, frog_id: 3>
:number
#<Observation id: 537, number: "1 to 5", comment: nil, created_at:
"2010-06-05 22:33:31", updated_at: "2010-06-05 22:33:41", survey_id:
612, frog_id: 3>
:"1"
#<Observation id: nil, number: nil, comment: nil, created_at: nil,
updated_at: nil, survey_id: nil, frog_id: nil>
:survey
#<Observation id: 538, number: "1 to 5", comment: nil, created_at:
"2010-06-05 22:33:31", updated_at: "2010-06-05 22:33:41", survey_id:
615, frog_id: 3>
:number
#<Observation id: 538, number: "1 to 5", comment: nil, created_at:
"2010-06-05 22:33:31", updated_at: "2010-06-05 22:33:41", survey_id:
615, frog_id: 3>
:"2"
#<Observation id: nil, number: nil, comment: nil, created_at: nil,
updated_at: nil, survey_id: nil, frog_id: nil>
:survey
#<Observation id: 541, number: "1 to 5", comment: nil, created_at:
"2010-06-05 22:33:31", updated_at: "2010-06-05 22:33:41", survey_id:
618, frog_id: 3>
:number
#<Observation id: 541, number: "1 to 5", comment: nil, created_at:
"2010-06-05 22:33:31", updated_at: "2010-06-05 22:33:41", survey_id:
618, frog_id: 3>
:"3"
#<Observation id: nil, number: nil, comment: nil, created_at: nil,
updated_at: nil, survey_id: nil, frog_id: nil>
:survey
#<Observation id: 566, number: "1 to 5", comment: nil, created_at:
"2010-06-05 22:33:31", updated_at: "2010-06-05 22:33:41", survey_id:
694, frog_id: 3>
:number
#<Observation id: 566, number: "1 to 5", comment: nil, created_at:
"2010-06-05 22:33:31", updated_at: "2010-06-05 22:33:41", survey_id:
694, frog_id: 3>
:"4"
#<Observation id: nil, number: nil, comment: nil, created_at: nil,
updated_at: nil, survey_id: nil, frog_id: nil>
:survey
#<Observation id: 535, number: "5 to 20", comment: nil, created_at:
"2010-06-05 22:33:31", updated_at: "2010-06-05 22:33:41", survey_id:
601, frog_id: 3>
:number
#<Observation id: 535, number: "5 to 20", comment: nil, created_at:
"2010-06-05 22:33:31", updated_at: "2010-06-05 22:33:41", survey_id:
601, frog_id: 3>
:"5"
#<Observation id: nil, number: nil, comment: nil, created_at: nil,
updated_at: nil, survey_id: nil, frog_id: nil>
:survey
#<Observation id: 570, number: "1 to 5", comment: nil, created_at:
"2010-06-05 22:33:31", updated_at: "2010-06-05 22:33:41", survey_id:
700, frog_id: 3>
:number
#<Observation id: 570, number: "1 to 5", comment: nil, created_at:
"2010-06-05 22:33:31", updated_at: "2010-06-05 22:33:41", survey_id:
700, frog_id: 3>
The first call has the field parameter set to an index number in the
set of child records but the model itself hasn't been populated with
the record data.
In subsequent calls the field parameter is set to the field being
displayed (I'm only displaying the survey and number attributes) and
the model has been populated.
Dean
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.