Hi everone,
I posted one question before early today, and I have made a little breakthrough
since then but I still got caught in one place and I''m not sure how to
resolve it. Anyone kind enough to read please give me any insight.
Basically I need to update a series of record on table work_times The
work_times table has following fields:
id, check_in, check_out, lunch , user_id, signed. The field signed is either 0
or 1 and 1 means the time sheet has been signed. Another table is users which
has field login, password, role_id, signed_by, signed_by represents who can sign
teh user id''s time sheet. Finally there is a table called roles that
classify users in 3 roles. One user has many work_times, and each work_times
belong to one user. each user belongs to one role. and one role has many users.
Now I am a user A who is looking at person B''s work_time records:
Using the tutorial 4 days of rails as an example, I create a sign.rhtml form as
below(excerpt)
<%=form_tag :action=>''sign_update'', :id=>params[:id]
%>
<table border ="1">
<%= render_collection_of_partials "signatures", @work_times%>
</table>
<%= submit_tag "Submit Signature" %>
<%=end_form_tag%>
%>
which the _signatures.rhtml reads as: (excerpt)
<tr valign="top">
.
<td
align="center"><%=check_box_tag("work_time["+signatures.id.to_s+"][signed]",
"1", signatures["signed"]==1)%>
<%=hidden_field_tag("work_time["+signatures.id.to_s+"][signed]","0")
%></td>
</tr>
Pressing the button Submit Signature will lead to a controller action
sign_update which I defined as belows:
def sign_update
@params[:work_time].each { |work_time.id, attr|
work_time = WorkTime.find(work_time.id)
work_time.update_attribute(:signed, attr[:signed])
}
redirect_to(:action=>''list'', :id=>session[:user].id)
end
------------------
The sign.rhtml seems to render correctly as when i look at the sources of html I
have something like this:
<td align="center"><input
id="work_time[12][signed]" name="work_time[12][signed]"
type="checkbox" value="1" />
<input id="work_time[12][signed]"
name="work_time[12][signed]" type="hidden"
value="0" />
</tr>......
......<td align="center"><input
id="work_time[13][signed]" name="work_time[13][signed]"
type="checkbox" value="1" />
<input id="work_time[13][signed]"
name="work_time[13][signed]" type="hidden"
value="0" />
</tr>
(12, 13...is the id of work_times table) (I don''t know why but in the
tutorial I saw the id field doesn;t have [:id] inside. do I make mistake here? )
but error comes out when I submit the form when sign_update action is invoked.
it says:
undefined local variable or method `work_time'' for
#<UserController:0x387fd90>
/app/controllers/user_controller.rb:61:in
`sign_update''/app/controllers/user_controller.rb:61:in
`each''/app/controllers/user_controller.rb:61:in
`sign_update''script/server:4
undefined local variable or method `work_time'' for
#<UserController:0x387fd90>
/app/controllers/user_controller.rb:61:in
`sign_update''/app/controllers/user_controller.rb:61:in
`each''/app/controllers/user_controller.rb:61:in
`sign_update''script/server:49
Anyone knows the reason would you please let me know?
Thank you for your time reading this.
Sammy
---------------------------------
DO YOU YAHOO!?
雅虎免费G邮箱-中国第一绝无垃圾邮件骚扰超大邮箱
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails