On Mon, 2009-08-10 at 11:38 -0700, djolley wrote:
[Taking things slightly out of order...]
> Thanks for any input. I'm totally at a loss:
Me too. At a loss, that is. So let me make sure I understand...
> Where the trouble arises is when I uncomment line 13 and pass the
> profile data to the view via the @profile instance variable. When I
> do that, things get all screwed up. Here is the output of the
> debugging files under that circumstance:
Let me make sure I understand what you're doing \ expecting via
the request \ response cycle as it applies to Rails.
The cycle starts when a request is made from the browser to a method in
a controller in the Rails app. In the simplest case, the controller
grabs data via its associated model and then passes that data via instance
variables to the associated view templates to render a response page.
Where the above doesn't make sense to me is that it implies that your
update() method is called from some page, renders a new page which then
calls it again. Is that right? If not, which cycle is the view
containing the select below involved in? Is it feeding update(), or
being generated via update() ?
> OK. Here's my controller code (line numbers assigned for
> convenience):
>
> 1 def update()
What is the purpose of the parens above?
> 2 outfile=File.open('/tmp/look1','w')
> 3 outfile.puts(params.inspect)
> 4 outfile.close
> 5 @member=Member.find(params[:id].to_i)
> 6 outfile=File.open('/tmp/look2','w')
> 7 outfile.puts(@member.inspect)
> 8 outfile.close
> 9 profile=Member.profile(@member.flags)
> 10 outfile=File.open('/tmp/look3','w')
> 11 outfile.puts(profile.inspect)
> 12 outfile.close
> 13 # @profile=profile
> 14 end
>
> As you can see, aside from the code which writes crucial data to
> respective disk files for debugging purposes, there are really only 3
> lines of code in the controller, line 5, line 9, and line 13 which is
> commented out. You may have noticed that lines 9 and 13 can easily be
> combined into a single line. I broke them apart to make clear that
> the problem is not in the model code.
>
> I invoke the code by entering 'http://my_host/members/update/15' into
> my browser.
What do you mean 'entering'? An update should be a POST or better yet a
PUT of a params hash that would come from a form. I don't understand
'entering'.
> With line 13 commented out, everything seems to work perfectly. Under
> that condition, here is what the contents of my debugging files looks
> like:
>
> $ cat /tmp/look1
> {"action"=>"update", "id"=>"15", "controller"=>"members"}
> $ cat /tmp/look2
> #<Member id: 15, login: "bob1", password: "ppss", flags: 2,
> first_name: "Bob", last_name: "Chaput", email: "[email protected]",
> courtesy_title: "Mr.", created_at: nil, updated_at: "2009-08-09
> 23:40:18">
This is an inappropriate use of the update method. Should be using
'show' here since all you're doing is GETting information about the
member.
> $ cat /tmp/look3
> [["1", "Members List"], ["0", "Other List 1"], [0, "Other List 2"]]
>
> The above results are exactly what is expected.
>
> Where the trouble arises is when I uncomment line 13 and pass the
> profile data to the view via the @profile instance variable. When I
> do that, things get all screwed up. Here is the output of the
> debugging files under that circumstance:
>
> $ cat /tmp/look1
> {"format"=>"gif", "action"=>"update", "id"=>"SpryMenuBarRightHover",
> "controller"=>"members"}
> $ cat /tmp/look2
> #<Member id: 0, login: "admin", password: "secret", flags: 0,
> first_name: "Admin", last_name: "Admin", email: "[email protected]",
> courtesy_title: "Mr.", created_at: nil, updated_at: "2009-08-09
> 18:03:42">
> $ cat /tmp/look3
> [["0", "Members List"], [0, "Other List 1"], [0, "Other List 2"]]
>
> So, somehow passing the profile data to the view via the @profile
> instance variable causes things to get screwed up. It appears that
> the cause of the problem is that for reasons unknown to me, the params
> are now totally wrong. That's the culprit. I just don't know what's
> causing it. Any ideas?
> Although I'm not sure what it has to do with the issue, here is my
> relevant view code:
What do you mean 'relevant'? What's the name of this template? And, at
a minimum, post the <%= form... %> line so we can understand the flow.
> <select name="flags[]" multiple="multiple" size="4" style="display:
> block; margin-left: auto; margin-right: auto;">
> <% index=0
> value=1
> @profile.each do |option| %>
> <%= "<option value=\"#{value}\" #{"selected='selected'" if option
> [0].to_i==1}>#{option[1]}</option>" %>
> <% index+=1
> value=2*value
> end %>
> </select>
Tell us about the other view templates and controller methods that are
involved here. Also, please post your Member model.
Best regards,
Bill
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" 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/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---