RankWeis
RankWeis

Reputation: 782

Rails: Where does new_*something*_path variable get set up?

I created a scaffold for 'messages', and new_message_path and edit_message_path (for use in link_to's) are all set up, but now I've created app/views/messages/sent.html.erb, and I want to do something along the lines of <%= link_to 'Sent', sent_message_path %>, but I can't figure out how to do that. I get

undefined local variable or method `sent_message_path' for #<ActionView::Base:0x103117c50>

Upvotes: 12

Views: 13470

Answers (3)

user124873
user124873

Reputation:

Those methods are created automatically when routes are defined and in the case of RESTful routes, they follow a predictable convention.

Running 'rake routes' is a helpful way of seeing all of the routes being generated.

I recommend you read: http://guides.rubyonrails.org/routing.html

Upvotes: 15

raid5ive
raid5ive

Reputation: 6642

Update your routes.rb to contain something along the lines of:

map.resources :messages, :collection => { :sent => :get }

This will create a new route for the sent action using GET.

Upvotes: 0

Sergey
Sergey

Reputation: 795

Answer for your question is situated at http://railsapi.com/doc/rails-v2.3.8/classes/ActionController/Resources.html

Upvotes: -1

Related Questions