This is sort of a beginner question. I learned how to generate RESTful links using rails helpers.
For instance, if I have a resource 'tweets',
<link_to "List all tweets", tweets_path> # link to /tweets/index
<link_to "New tweets", new_tweets_path> # link to /tweets/new
<link_to "Show a tweet", tweet_path(:id)> # link to /tweets/show/:id
<link_to "List all tweets", edit_tweets_path(:id)> # link to /tweets/edit/:id
I can use such helpers as create_tweets_path, update_tweets_path, or delete_tweets_path?
In other words,
<link_to "Create", some_tweet, method: post>
<link_to "Create", create_tweets_path(some_tweet)>
<link_to "Update", some_tweet, method: put>
<link_to "Update", update_tweets_path(some_tweet)>
Are these pairs equivalent expressions?
Not really. See here: http://guides.rubyonrails.org/routing.html
The same helpers are used for GET and POST commands, and rails uses the HTTP action to differentiate between the two. IE: tweets_path in your example can either be a GET (#index action), or POST (#create action)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.