views:

24

answers:

2

Hello, I have a model photo

which allows me to load URLs like

  • /photos
  • /photos/2
  • /photos/2/edit

Edit allows the user to change the image, but I want a different kind of edit for permission type stuff specific to the app I'm building, which would look like:

  • /photos/2/updatesettings

So in the photos controller I added "def updatesettings ...."

And in the routes I added:

resources :photos do
 collection do
    get 'updatesettings'
 end
end

But I'm getting an error: "Routing Error No route matches"

Suggestions? thanks

+1  A: 

There is a high chance you're using a form to update these settings, am I right?*

In which case you want to do post 'updatesettings' in your routes file, not get. This will define a route that responds to POST requests, vs one that only responds to GET requests. If you want both then use a get and a post line in your routes file.

* Most of the time, yes I am.

Ryan Bigg
Well I need a ShowSettings to render an HTML page showing all the settings... Then I guess I'll need an updatesettings to Post to ?
AnApprentice
I do have a permissions table that handles all this stuff. Maybe this belongs in that controller...
AnApprentice
+1  A: 

What you have in your routes file will match the url '/photos/updatesettings'

The only way I know how to do what you want to do is:

match "photos/:id/updatesettings" => "photos#updatesettings"

In the second part of that line, photos is telling it to look in the photos controller, and #updatesettings is telling it the method to call.

You would put this outside of resources :photos, so your code would be

resources :photos
match "photos/:id/updatesettings" => "photos#updatesettings"