简体   繁体   English

Rails表单提交有2个表单的问题

[英]Rails form submit problem having 2 forms

I have that problem it is always the same form that gets submitted. 我有一个问题,那就是总是提交相同的表格。 The update_limits action gets called on the update order submit button. 在更新顺序提交按钮上调用update_limits操作。 Which should trigger the action update_order. 哪个应该触发动作update_order。

Here is my view: 这是我的看法:

<h2>Movies</h2>
<h3>List movies</h3>
<%= form_tag(:action => 'update_limits' ,:id => params[:id]) %>
<%= link_to 'create new movie', {:action => 'create',:id => params[:id]}, {:class => 'margin-left'} %>
<div class="spacer">&nbsp;</div>    

Number of movies in reel:
<span class="c1">
<% rr = 1..6 %>
<%= select("limits", "reel_limit", rr) %> 
</span>
Number of movies in archive:
<span class="c1">
<% rr = 0..12 %>
<%= select("limits", "archive_limit", rr) %> 
</span>
<%= submit_tag %>
<div class="spacer">&nbsp;</div>    
<%= form_tag(:controller => 'admin/photographers', :action => 'update_order' ,:id => params[:id]) %>
<ul id='movielist'>
<span class="header">name</span>
<% 
n = 0 
while n < @items.length
%>
<li itemID='<%=@items[n].id%>' <%= reel_color_class(n, @limits) %>>
<% if @items[n]["image"] %>
<%= image_tag("/photographer/image/#{@items[n].id}/#{@items[n]["image"]}", :size => "36x20" ) %>
<% end %>
<%=@items[n].name.force_encoding("UTF-8") %>
<span class='col2'>
<%= link_to 'edit', {:action => "edit", :id => @items[n].id}  %>
<%= link_to("remove", {:action => "remove", :id => @items[n].id }, 
{:confirm => "Are your sure?"}) %>
</span>
</li>
<%
n = n + 1 
end 
%>
</ul>
<input type="hidden" name="neworder" id="neworder" value="" />
 <input name="commit" type="submit" value="update order" onclick="neworder.value=(junkdrawer.inspectListOrderNew('movielist'))" />
<div class="spacer">&nbsp;</div>

The form_tag method takes a block, and you are not giving it one. form_tag方法有一个块,您没有给它一个。 You should be doing something like this: 您应该这样做:

<%= form_tag(:action => 'update_limits' ,:id => params[:id]) do %>
# form goes here
<% end %>

Or even better, if this is acting on a real object, using a form_for tag: 甚至更好,如果这是作用于真实对象,则使用form_for标记:

<%= form_for(@object) do |f| %>
# form_goes here
<% end %>

For more information, please read the Getting Started guide for Rails . 有关更多信息,请阅读Rails入门指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM