Link_to_remote with nested routes

I am trying to figure out how to structure my path in the link_to_remote tag to accommodate nested routes. I have an article model that relates to a group model, and the article has votes associated with it (using the Vote_Fu plugin). At first I created the code for the articles, and it worked, but in the process of adding a group model and updating my paths for everything, the link below is now broken. I know that he is looking for new_question_path, which will no longer work, but I cannot figure out what to replace it with.

<%= link_to_remote "+(#{@article.votes_for})",   
  :update=>"vote", 
  :url => { :controller=>"articles",
            :action=>"vote",  
            :id=>@article.id,  
            :vote=>"for"},
            :html => { :class  => "up" } %>

Any help would be awesome. Thank!

UPDATE:

Looks like the problem was in my routes. I have a voting method in my article controller, but he did not know what to look for. I changed the routes.rb file to this:

group.resources :articles, :member => { :vote => :get }

It looks like the problem can be solved.

+3
1

, : . , , , has_many: .

VotesController, map.resources :articles, :has_many => :votes, URL-, /articles/ 1/votes ..

, , , , ..

, , . , . RESTful , :)

+1

Source: https://habr.com/ru/post/1732406/


All Articles