我要轉移的:行動是用戶選擇到下一個頁面如何傳輸select_tag參數button_to
index.html.erb
<td><%= select_tag :action, options_for_select(actions[account.type])%>
<%= button_to "execute", {:controller => "records", :action => "new", :type => :action, :account_name => account.name}, class: "btn btn-primary" %></td>
new.html.erb
<%= form_for @record do |f| %>
<%= f.hidden_field :type, value: :type %>
<%= f.hidden_field :account_name, value: params[:account_name] %>
<div class="actions">
<%= f.submit "Submit", class: "btn btn-primary" %>
</div>
<% end %>
RecordController
class RecordsController < ApplicationController
def index
@records = Record.all
end
def new
@record = current_user.records.build
end
def create
@record = current_user.records.build(create_params)
if @record.save
flash[:success] = "Posted successfully"
redirect_to('/root/tally_book')
else
redirect_to('/root/tally_book')
end
end
def destroy
@record = current_user.records.find_by(id: params[:id])
if @record && @record.destroy
flash[:success] = "Post deleted"
else
flash[:error] = "Cannot delete post"
end
redirect_to('/root/tally_book')
end
private
def create_params
params.require(:record).permit(:account_name, :description, :usage, :type, :sum, :receipt)
end
end
的ACCOUNT_NAME成功
發送,但其類型變得字「型」,而不是用戶選擇
如何轉移:用戶類型選擇?
用表格把它包起來,並使用提交.. – Nithin