2016-07-16 8 views
0

と一致していない各ユーザーは、ブログの数を作成することができると、彼らはログインしたとき、彼らは自分のブログのリストと、以下のように次の各ボタンが提示されていますRailsのシンプルなフォーム - Noルートは

= simple_form_for activate_blog_path(blog.id), method: :put do |f| 
    = hidden_field_tag :active, value: true 
    = f.button :submit 

No route matches [PUT] "/" 

routes.rbを::

resources :users 
resources :blogs do 
    member do 
    get :activate 
    put :activate 
    end 
end 
root 'pages#index' 

レールパスがルートに存在するにもかかわらず、私はまだ、このエラーメッセージが出ていルートは:

 Prefix Verb URI Pattern     Controller#Action 
     users GET /users(.:format)    users#index 
       POST /users(.:format)    users#create 
    new_user GET /users/new(.:format)   users#new 
    edit_user GET /users/:id/edit(.:format)  users#edit 
     user GET /users/:id(.:format)   users#show 
       PATCH /users/:id(.:format)   users#update 
       PUT /users/:id(.:format)   users#update 
       DELETE /users/:id(.:format)   users#destroy 
activate_blog GET /blogs/:id/activate(.:format) blogs#activate 
       PUT /blogs/:id/activate(.:format) blogs#activate 
     blogs GET /blogs(.:format)    blogs#index 
       POST /blogs(.:format)    blogs#create 
    new_blog GET /blogs/new(.:format)   blogs#new 
    edit_blog GET /blogs/:id/edit(.:format)  blogs#edit 
     blog GET /blogs/:id(.:format)   blogs#show 
       PATCH /blogs/:id(.:format)   blogs#update 
       PUT /blogs/:id(.:format)   blogs#update 
       DELETE /blogs/:id(.:format)   blogs#destroy 
     root GET /       pages#index 

blogs_controller.rb:

def activate 
    @blog.active = true 
    @blog.save 
    redirect_to root_path 
    end 

は、私がここで間違って何をしているのですか?

+0

完全なエラーメッセージを投稿できますか? – Pavan

+0

それはすべてです。 –

+0

必須キー ':id'が欠けているようなことがありましたか? – Pavan

答えて

1
= simple_form_for blog, url: url_for(action: :activate, controller: 'blogs'), method: :put do |f| 

simple_form_forオブジェクト(またはレコード)がフォームタグを生成するために期待アクションコントローラ、ならびに方法を指定する必要があります。カスタムURLとメソッドをフォームアクションに渡すには

= simple_form_for blog, url: activate_blog_path(blog.id), method: :put do |f| 
    = hidden_field_tag :active, value: true 
    = f.button :submit 
+0

ありがとう!それはうまくいった! –

-1

あなたは

+0

私はこのエラーを受け取ります:ルートは{:action => "activate"、:controller => "blogs"}と一致しません –

+0

私にとってはうまくいったとしてエラーが発生したのが不思議です。 – margo

関連する問題