I have a question about the 5th video 'Routing into darkness'.
At about 3 minutes 44 seconds Greg is describing how to set up a link_to using a custom route. A line appears saying "tweets_path wouldn't work".
I'd like to know WHY tweets_path wouldn't work. I'm hoping knowing why will help demystify Rails some more. At the moment that line seems a bit arbitrary and I'd like to make sense of it.
EDIT
Sorry, for some reason I was thinking you'd need to see the video. Here's the relevant code:
In his routes.rb file:
get '/all' => 'tweets#index'
And in a view, somewhere:
<%= link_to "All Tweets", ?? %> # tweets_path wouldn't work
tweets_path
won't work here because there isn't a route called 'tweets_path' in his routes.rb file. The only routes that he has (at least that we can see) is the '/all' route, which goes to the tweets controller and index action. If Greg put resources :tweets
in his routes.rb file, then tweets_path
would work. Also, if you have the code get '/all' => 'tweets#index'
(i.e. without as: 'all_tweets'
), then all_path
will work. With as: 'all_tweets'
, then only all_tweets_path
will work