0
我有很多link_tos,用於基於當前用戶在數據庫中創建記錄。通過增加一個下拉菜單,在當前用戶可以選擇他想要代表創建記錄該用戶前 -通行證下拉值LINK_TO
我想當前用戶能夠代表其他用戶的添加記錄。
我有下面的代碼,這需要進行調整,以滿足上述需求 - 任何幫助,請:)
<%= collection_select(:user, :id, User.where(:department_id => current_user.department_id).all, :id, :firstname, :selected => current_user.id) %>
<% @myTemplates.where(:pickable => true).each do |template| %>
<%= link_to shifts_path(:template_id => template.id, :shift_date => date), :method => :post do %>
<%= template.type.name %>
<% end %>
<% end %>
在我試圖不工作下列控制器 - 得到一個NillClass錯誤。
params[:user][:id]
編輯:
21:38:38 web.1 | Started POST "/shifts?shift_date=2013-03-19&template_id=2" for 127.0.0.1 at 2013-03-19 21:10:31 +0100
21:38:38 web.1 | Processing by ShiftsController#create as HTML
21:38:38 web.1 | Parameters: {"authenticity_token"=>"PMpPcxD9f1xh/KmTx2f0b8KZkYu91Q3n3zM7f5ie4zU=", "shift_date"=>"2013-03-19", "template_id"=>"2"}
21:38:38 web.1 | User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1
21:38:38 web.1 | Template Load (0.1ms) SELECT "templates".* FROM "templates" WHERE "templates"."id" = ? LIMIT 1 [["id", "2"]]
21:38:38 web.1 | Completed 500 Internal Server Error in 2ms
21:38:38 web.1 |
21:38:38 web.1 | NoMethodError - undefined method `[]' for nil:NilClass:
21:38:38 web.1 | app/controllers/shifts_controller.rb:14:in `create'
21:38:38 web.1 | (gem) actionpack-3.2.11/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
21:38:38 web.1 | (gem) actionpack-3.2.11/lib/abstract_controller/base.rb:167:in `process_action'
21:38:38 web.1 | (gem) actionpack-3.2.11/lib/action_controller/metal/rendering.rb:10:in `process_action'
21:38:38 web.1 | (gem) actionpack-3.2.11/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
21:38:38 web.1 | (gem) activesupport-3.2.11/lib/active_support/callbacks.rb:436:in `_run__200718806994229589__process_action__4067499974676832569__callbacks'
21:38:38 web.1 | (gem) activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `__run_callback'
21:38:38 web.1 | (gem) activesupport-3.2.11/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
21:38:38 web.1 | (gem) activesupport-3.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
21:38:38 web.1 | (gem) actionpack-3.2.11/lib/abstract_controller/callbacks.rb:17:in `process_action'
...
...
我創建行動包含以下
@template = Template.find(params[:template_id])
submission_hash = {"user_id" => params[:user][:id],
"type_id" => @template.type_id,
"paytypes_id" => @template.paytypes_id,
"shiftdate" => params[:shift_date],
"shiftstart" => @template.shiftstart,
"shiftend" => @template.shiftend}
@shift = Shift.new(submission_hash)
謝謝..我如何解析控制器下拉的帕拉姆?如果我無法傳遞link_to命令,如何從控制器中檢索選定的下拉列表值。希望我的問題是有道理的:) – Twiddr 2013-03-19 19:18:50
,要是你給它在select_tag名稱字段這將是params哈希表 – 2013-03-19 19:48:50
利用Just編輯我的問題。在控制器中添加了collection_select標籤和params調用。我似乎無法使其工作。有任何想法嗎? – Twiddr 2013-03-19 20:14:24