Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails3 custom controller method not routed: works in Rails2

I've been using Rails 2.3.8 for a project that I've been working on, but have just migrated the project over to Rails 3.0.3. After ironing out the basic bugs, I've got a problem now with a custom controller method.

In the gallery_controller, I had a custom method called 'extract'. In rails 2.3.8, this worked fine, no extra configuration. I could go to /galleries/extract/:id and it would do what I wanted it to.

Now that code breaks the app when I try to create a link to it with the original code in the form:

<%= link_to "Add photos to gallery from: ",
        :action => 'extract', :id => @gallery.id %>

and the error I get when I try to go to the page with this code on it:

No route matches {:action=>"extract", :controller=>"galleries", :id=>2}

After looking at routes.rb, I've come to suspect that this fails because the

match ':controller(/:action(/:id(.:format)))'

is not included, and is in fact deprecated.

Running rake tasks | grep 'extract' gives me nothing.

So how should I fix this?

like image 434
Josh Kovach Avatar asked Dec 01 '25 05:12

Josh Kovach


1 Answers

See the Routing Guide: Adding More RESTful Actions. You need to tell your application's routes about the extract action, with something like this:

resources :gallery do
  get 'extract', :on => :member
end
like image 70
wmorgan Avatar answered Dec 04 '25 06:12

wmorgan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!