OK. Here's my controller code (line numbers assigned for
convenience):
1 def update()
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.
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: "bob@rchapix.com",
courtesy_title: "Mr.", created_at: nil, updated_at: "2009-08-09
23:40:18">
$ 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: "foo@bar.com",
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:
<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>
Thanks for any input. I'm totally at a loss:
...doug