一个form表单中不同button响应不同action

方法一:(适合只有某个参数不一样)
VIEW中:
<% form_for @course,:url => { :controller=> "team_select_edit_update"} do |f| %>
  <%for team in course_teams%>
	<td><%= f.submit "分配到"+"#{team.name}"%></td>
  <%end%>		
<%end%>	

CONTROLLER中:
team=Team.find(:first,:conditions=>"name='#{params[:commit].delete('分配到')}'}")

方法二:(适合方法操作不一样)
VIEW中:
<% form_remote_tag :url => { :controller => 'student_active_marks'}, 
	:update => 'all', 
	:html => { :name => 'myaccs2' } do -%>

<%= hidden_field_tag 'form_action' %>
<input type="hidden" id="cad_active_id" name="cad_active_id" value="<%=@cad_active.id%>">

<%=submit_tag "添加学生", :name => "contact",:class=>"button" ,  :onClick =>      "document.myaccs2.form_action.value='contact' "%>
	
<%=submit_tag "参与确认", :name => "sure",:class=>"button" ,  :onClick => "document.myaccs2.form_action.value='sure' "%>	
			
<%=submit_tag "发电子邮件", :name => "email",:class=>"button" , :onClick => "document.myaccs2.form_action.value='email'"%>

<%@cad_student_actives.each do |cad_student_active|%>
<%= check_box_tag "active[stu_reg_inf_ids][]",cad_student_active.stu_reg_inf_id%>
<%end%>

<%end%>

CONTROLLER中:

 unless params[:active].nil?                    
        case params[:form_action]
        when "contact"         
        when "email"
        when "sure"          
        end   
     else
 render :text => "请至少选择一条记录进行操作!<a href='/actives/#{params[:cad_active_id]}'>请返回操作</a>",:layout=>"part_cad"
     end



小发现: flash 中可以插入链接<a href='/actives/#{params[:cad_active_id]}'>
         字符串切割String.delete('分隔')
         数组同样适用@student=[]
         for stu in stus
              @students<<stu  #数据插入
         end
         for stu in stus
              @students.delete stu #数组删除
         end



你可能感兴趣的:(form)