views:

197

answers:

2

Hi Guys,

I am have started learning Rails, it was going good until now.

I am using HAML and have this on my index.haml

= submit_to_remote "submit_btn", "Create", :url => {:controller => "queries", :action => "create"}, :method => "post"

= submit_to_remote "exe_btn", "Execute", :url => {:controller => "queries", :action => "execute"}, :method => "post"

It gives me back this error when trying to run it

No route matches {:controller=>"queries", :action=>"execute"}

As soon as I removed this line

= submit_to_remote "exe_btn", "Execute", :url => {:controller => "queries", :action => "execute"}, :method => "post"

It works without a problem.

Does anyone know what I am doing wrong and have any advice for me?

Cheers

Eef

+4  A: 

Modify the queries resource in config/routes.rb

map.resources :queries, :member => { :execute => :post}

If you don't have a query id submitted with the form then let it:

map.resources :queries, :collection => { :execute => :post}

Restart the server.

This is happening because the default map.resources gives you only 7 routes for the resource:

index, new, create, edit, update, show and delete.

Now as you want a new route called execute then you need to extend the routes as described above.

khelll
Cheers for the quick response! Works fine now. Thanks again!!
Eef
A: 

Have you created a route on your config/routes.rb file that corresponds to :controller => "queries", :action => "execute" ?

I'd guess you have a route like:

map.resources queries

Which tells Rails to define some RESTful routes for that model. When you try to reference the other route, Rails can't find it and asks for it.

You should fix it using:

map.resorces queries, :member => {:execute => :post}

which will then map it correctly to your action.

Yaraher