rails two buttons in a search form -
i have form_tag in index page performing searches on model.
<%= form_tag( :method => "get", :class => "form-inline") %> in form have 2 submit buttons should direct 2 different actions (two different views of displaying search results.
<div class="btn-group"> <%= submit_tag("view1", :class => 'btn btn btn-success', :name => 'view1') %> </div> <div class="btn-group"> <%= submit_tag("view2", :class => 'btn btn btn-primary', :name => 'view2') %> </div> when view1 submit clicked, point view1 action , load page same view 2.
so in controller did following:
def index if params[:view1] render :action => 'view1' elsif params[:view2] render :action => 'view2' end respond_to |format| format.html #{ render :layout => false }# index.html.erb end end but when submit form redirects save action apparently. url constructed http://0.0.0.0:3000/posts?class=form-inline&method=get instead of http://0.0.0.0:3000/view1?utf8=%e2%9c%93.....
what missing here?
def index if params[:view1] @action = '/some/url' else @action = '/some/url' end end changing url in form
<%= form_for('',url: view1) |f| %> --- fileds-- <%= submit_tag('conditional text') %> <% end %>
Comments
Post a Comment