У меня есть контроллер с именем Vote_controller.rb . В этом файле есть следующее действие:
class VotesController < ApplicationController
def vote_up
@post = Post.find(params[:post_id])
vote_attr = params[:vote].merge :user_id => current_user.id, :polarity => 1
@vote = @post.votes.create(vote_attr)
end
(и т.д. ...)
Я хочу вызвать действие vote_up
в представлении:
просмотров / сообщений / show.html.erb:
<%= link_to "Vote Up", ??? %>
Вот весь файл на всякий случай:
<h2>posts show</h2>
<span>Title: <%= @post.title %></span><br />
<span>Content: <%= @post.content %></span><br />
<span>User: <%= @post.user.username %></span><br />
<%= link_to "Vote Up", ??? %>
<h2>Comments</h2>
<% @post.comments.each do |comment| %>
<p>
<b>Comment:</b>
<%= comment.content %>
</p>
<p>
<b>Commenter</b>
<%= link_to comment.user.username, comment.user %>
</p>
<% end %>
<h2>Add a comment:</h2>
<%= form_for([@post, @post.comments.build]) do |f| %>
<div class="field">
<%= f.label :content %><br />
<%= f.text_area :content %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<% if current_user.id == @post.user_id %>
<%= link_to 'Edit', edit_post_path(@post) %> |
<% end %>
<%= link_to 'Back', posts_path %>
Понятия не имею, что набирать в ??? часть (я также хотел бы, чтобы это работало как :remote
. Я намерен запустить действие, не обновляя страницу).
Должен ли я что-то добавить в routes.rb
?
Есть предложения?