[英]Rails: URL being processed by incorrect controller action
我有一個錯誤的控制器操作正在處理的URL。 在我的路線文件中,我有以下內容
post '/tweets' => 'tweets#create'
每當我發布到此url時,它都會由tweets#index
。
Started POST "/tweets" for 127.0.0.1 at 2014-03-27 20:04:25 -0700
Processing by TweetsController#index as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"CCN9rDQiSXkVK0sF/BGU19fIufJTpho/ocySPmu7Lsc=", "tweet"=>{"title"=>"sdfdsafdsa", "description"=>"sdfdsasdadsa", "user_id"=>"1"}, "commit"=>"Create Tweet"}
Tweet Load (0.4ms) SELECT `tweets`.* FROM `tweets`
Rendered tweets/index.html.erb within layouts/application (0.1ms)
Completed 200 OK in 42ms (Views: 40.6ms | ActiveRecord: 0.4ms)
我嘗試重新啟動Rails服務器,但仍然無法正常工作。
這是rake routes
的結果
tweeter: rake routes
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
tweets /tweets(.:format) tweets#index
tweets_new /tweets/new(.:format) tweets#new
POST /tweets(.:format) tweets#create
root / tweets#index
那是因為您在其他tweet
路由之后定義了post '/tweets' => 'tweets#create'
。
通過將此行移至其他tweet
路由上方來修改您的路由配置:
# config/routes.rb
...
post '/tweets' => 'tweets#create'
resources :tweets, only: [ :index, :new ]
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.