我在Posts控制器中创建了一个新动作,但似乎我无法访问它。
动作名称为'kill',因此当我在浏览器中输入localhost:3000 / posts / kill
我收到以下错误:Couldn't find Pad with id=kill
Extracted source (around line #18
def show
@post_selected = Post.find(params[:id])
@posts = Post.all
end
在我的routes.rb
中resources :posts
match ':controller(:action(/:id))', :via => [:get, :post]
match "/pads/modifier" => "pads#modifier", :via => [:get]
当我输入rake路线时,这就是我得到的
Prefix Verb URI Pattern Controller#Ac
posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new
edit_post GET /posts/:id/edit(.:format) posts#edit
post GET /posts/:id(.:format) posts#show
PATCH /posts/:id(.:format) posts#update
PUT /posts/:id(.:format) posts#update
DELETE /posts/:id(.:format) posts#destroy
root GET / posts#welcome
GET|POST /:controller(:action(/:id))(.:format) :controller#:
posts_modifier GET /posts/modifier(.:format) posts#modifier
如何生成获取新创建的动作'kill'的路径?
============================================ ============= 更新#1 :已解决,
除了下面的答案,我还可以通过以下代码实现这一目标
resources :posts, controller: 'posts' do
get 'posts/:action', to: 'posts#:action'
end
============================================ ===============
答案 0 :(得分:1)
get 'posts/kill', to: 'posts#kill'