Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7400339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:14:07+00:00 2026-05-29T04:14:07+00:00

I have a controller called votes_controller.rb . In that file there is the following

  • 0

I have a controller called votes_controller.rb. In that file there is the following action:

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

(etc…)

I want to trigger the vote_up action in a view:

views/posts/show.html.erb::

<%= link_to "Vote Up", ??? %>

Here is the whole file just in case:

<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 %>

I have no idea what to type in the ??? part (I would also like to make it work as :remote. My intention is to trigger the action without refreshing the page).

Do I have to add something in the routes.rb?

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:14:08+00:00Added an answer on May 29, 2026 at 4:14 am

    You have to define a route in routes.rb. Use a named route to be easy to use in the view. Something like:

    get 'votes/:id/vote_up' => 'votes#vote_up', as: 'vote_up'
    

    And so can now use in the view

    <%= link_to "Vote Up", vote_up_path(@post) %>
    

    and in the controller

    def vote_up
      @post = Post.find(params[:id])
      ...
    end
    

    See Rails routing

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a controller which has a method called history class UsersController < ApplicationController
I have a action on my controller (controller name is 'makemagic') called 'dosomething' that
If I have an ASP.NET MVC controller action that is called from a jQuery
I have a controller called Account with an action with the following signature: public
I have a controller called MetricsController with a single action method: public class MetricsController
I have a controller action that allows a user to download a file with
I have a controller that is called with AJAX (sends JSON data), so I
I have a page. (action) and a controller called Widget. im passing in client
I have a div called test and mvc action in the client controller The
So I have a controller called Music with one action which is index. On

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.