RAILS3: Pass arbitrary parameters via button_to?

后端 未结 5 1967
北海茫月
北海茫月 2020-12-30 04:02

I\'m trying to do something very simple in my first Rails app (Rails 3) and I\'m not sure what I\'m doing wrong, or if there\'s a better approach. Can\'t find anything on th

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-30 04:40

    Add this line of code in your routes.rb file.

    resources :work_requests do
      member do 
        post 'new'
      end
    end
    

    It shouldn't be the GET method because you're sending information to the server, via :module_id. This will then work.

    <%= button_to("Add WorkRequest", {:controller => "work_request", :action => "new", :article_id => @article.id})%>
    

提交回复
热议问题