Skip to content

Instantly share code, notes, and snippets.

@magicmarkker
Created July 17, 2014 18:56
Show Gist options
  • Save magicmarkker/925f603fa6ec5d8b29ac to your computer and use it in GitHub Desktop.
Save magicmarkker/925f603fa6ec5d8b29ac to your computer and use it in GitHub Desktop.
# routes.rb
resources :committees, as: :workrooms, path: :workrooms do
resources :meetings, concerns: :bookable
end
# Generates
# workroom_meeting_book GET /workrooms/:workroom_id/meetings/:meeting_id/books/:id(
polymorphic_path([@workroom, @meeting, @book])
# But since @workroom is really a Committee model
# It's generating: committee_meeting_book_path :(
@r38y
Copy link

r38y commented Jul 17, 2014

What does [@workroom, @meeting, @book] come out as? Where does polymorphic_path come from?

@r38y
Copy link

r38y commented Jul 17, 2014

Actually, I don't think polymorphic_path is using your routes at all. You would probably be better off not using it or living with what it gives you.

@magicmarkker
Copy link
Author

@r38y @workroom is a Committee AR result, same with meeting and book, however, if I remove @workroom it works because the other two models aren't aliased. @workroom is really the committee.rb model file, but I have it aliased in the routes file. The polymorphic_path is what im using to redirect instead of having 5 if/else redirects in all of my controllers.

@magicmarkker
Copy link
Author

Lame, trying to refactor all of these if/else to get rid of some code smell

@magicmarkker
Copy link
Author

Fixed it by changing the route to this:
resources :workrooms, as: :committees

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment