开发者

Multiple posts handled by links and named routes in Rails

I have a controller tavern and in the index there can be some actions. There will be two different posts for different reasons, and i want those posts to happen in link_to.

My route is now :

  scope :path => '/tavern', :controller => :tavern do
    get '/' => :index, :as => 'tavern'
    post 'quest/:quest_type' => :new_quest
  end   

The index action renders the main page and a post request can be made, also specifying a :quest_type that equals to 1,2,3 or 4. In开发者_开发问答 the process, another post will be made, for a different things that i want to achieve.

The question now is, how do i properly create a link_to to handle a post ?

I made something like :

<%= link_to "Take up an Easy Quest (4 minutes)", tavern_path('1'), :method => :post %>

Which does not give an error, but results to link to /tavern.1, which i think is not correct.

What is the proper way to do it here ?

UPDATE :

After searching a bit, i tried changing the route to :

post 'quest/:quest_type' => :new_quest, :as => 'get_quest'

and the link to :

    <%= link_to "Take up an Easy Quest (4 minutes)", get_quest_path(:quest_type => '1'), :method => :post %>

I'd swear that this worked some time, but it won't work now. I'm getting no route matches /tavern/quest/1


Fixed it, it was a problem with installing jquery. I had to remove SSL and reinstall jquery and my updated above worked fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜