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 8968723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:29:39+00:00 2026-06-15T17:29:39+00:00

I have a blogging application that has posts that can receive votes through a

  • 0

I have a blogging application that has posts that can receive votes through a vote action in the posts controller.
Because I allow voting in both the index and show views, I redirect_to :back after a vote is made, as below.

def vote
  # voting logic goes here
  redirect_to :back
end

This redirects me to the correct page, but I want to redirect to the specific post within the page. To do this, I added an identifying anchor to my post partial div.

<div id="post_<%= post.id %>">
  <%= post.content %>
</div>

How can I reference this in my redirect_to :back? I tried the below, which doesn’t work.

# this doesn't work!
redirect_to :back, anchor: "post_#{@post.id}"

Alternatively, if I were to use an if clause for the show and index views, how do I do that? I tried the below, which returns undefined method 'current_page' for VocabsController.

#this doesn't work!
if current_page?(posts_path)
  redirect_to posts_path(anchor: "post_#{@post.id}"
else
  redirect_to @post
end
  • 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-06-15T17:29:40+00:00Added an answer on June 15, 2026 at 5:29 pm

    I ended up using Javascript instead.

    posts_controller.rb

    def vote
      @post = Post.find(params[:id])
      #voting logic
      respond_to do |format|
        format.html { redirect_to :back }
        format.js
      end
    end
    

    posts/_post.html.erb

    <div class="post_partial" id="post_<%= post.id %>">
      <%= post.content %>
      <div id="vote_button_<%= post.id %>">
        <%= link_to "up", vote_path, method: "post", remote: true %>
      </div>
    </div>
    

    posts/vote.js.erb

    $('#post_<%= @post.id %>').html('<%= j render @post %>');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a blogging application with comments. Currently, the comments controller has a standard
I have a blogging application in which User has_many posts. I am using pagination
I want to have sort of live blogging that will allow a reporter to
Say I have a blogging app in Django. How can i re-order the posts
I am writing a basic blogging application in ASP.NET MVC. I have a Post
I have a certain amount of characters that I can fit in the spot
We have an audio blogging website which can be configured to publish links to
I have got a requirement from a client. They need three blogging web application
I would like to have a good blogging application developed in Ruby On Rails,
I am looking for a blogging platform that has built in tools for programming-related

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.