AnApprentice
AnApprentice

Reputation: 110960

Rails 3- Understanding the Controller/Routes relationship

which allows me to load URLs like

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:

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

Upvotes: 0

Views: 198

Answers (2)

dpieri
dpieri

Reputation: 166

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"

Upvotes: 1

Ryan Bigg
Ryan Bigg

Reputation: 107728

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.

Upvotes: 1

Related Questions