Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails button_to: how to specify the controller?

I don't understand what's happening here. I want to put a button_to in my (haml) view. If I do this:

=button_to( "New", {:action => "new"}, {} )

the page generated has:

<form action="/cached_input_files/new" class="button_to" method="post">
  <div>
    <input type="submit" value="New" />
    <input name="authenticity_token" type="hidden" value="..blah.." />
  </div>
</form>

which is OK, but I need to address a different controller. But if I try to specify the controller:

=button_to( "New", {:action => "new", :controller => "editor"}, {} )

I get:

<form action="/assets?action=new&controller=editor" class="button_to" method="post">
  <div>
    <input type="submit" value="New" />
    ...

I expected the action to be "/editor/new", and I have no idea why it isn't, nor how to correctly specify the controller I want to route to.

I'm using Rails 3.2.1.

like image 435
Ian Dickinson Avatar asked Feb 29 '12 15:02

Ian Dickinson


2 Answers

You don't want to include the options in their own hash, I think this is confusing the interpreter.

=button_to( "New", :action => "new", :controller => "editor")

should do what you want.

like image 188
TheDelChop Avatar answered Sep 28 '22 01:09

TheDelChop


Try

=button_to( "New", new_editor_path, :method => :get )
like image 39
Syed Aslam Avatar answered Sep 28 '22 03:09

Syed Aslam