0

I have a form_tag in my index page for performing searches on my model.

 <%= form_tag( :method => "get", :class => "form-inline") do %>

In the form I have two submit buttons that should direct to two different actions (two different views of displaying the 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 the view1 submit is clicked, I would like to it to point to the view1 action and load that page same as for view 2.

So in my controller I did the following:

  def index
    if params[:view1]
          render :action => 'view1'
      elsif params[:view2]
          render :action => 'view2'
      end
      respond_to do |format|
        format.html #{ render :layout => false }# index.html.erb        
      end
  end

but when I submit the form it redirects to the save action apparently. The url that is constructed is http://0.0.0.0:3000/posts?class=form-inline&method=get instead of something like http://0.0.0.0:3000/view1?utf8=%E2%9C%93.....

What am I missing here?

2 Answers 2

0
def index
if params[:view1]
 @action = '/some/url'
else
  @action = '/some/url'
end

end

Changing url in form

<%= form_for('',url: view1) do |f| %>
--- fileds--
<%= submit_tag('conditional text') %>
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

0

got this to work

     <%= form_tag(root_path,  :method => "get", :class => "form-inline") do %>


   <%= submit_tag("view1", :class => 'btn btn btn-success', :name => 'view1') %>
   <%= submit_tag("view2", :class => 'btn btn btn-success', :name => 'view2') %>




if params[:view1]
     render :action => :view1


  elsif params[:view2]
     render :action => :view2
  end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.