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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:47:04+00:00 2026-05-25T13:47:04+00:00

I am trying to pass along a local variable to a partial using link_to.

  • 0

I am trying to pass along a local variable to a partial using link_to. I have tried many different things, but it doesn’t seem to work. The js file loads the partial fine, it just doesn’t have the locals. This is what I have, thanks for any direction!

_health.html.erb (this is a partial on index.html of Contacts model)

<% @comments = Comment.find_all_by_api(@api) %>
<%= link_to 'Read Comments', comments_path(:comments => @comments), :action => 'comments',  :remote => true %> 

comments.js.erb

$("#comments").html("<%= escape_javascript(render(:partial => 'comment', :locals => {:comments => :comments})) %>");

comment.html.erb

<% unless @comments.blank? %>
 <% @comments.each do |c| %>

   <%= c %><br />

 <% end %>
<% end %>

contacts_controller.rb

  def comments  
   respond_to do | format |  
      format.js {render :layout => false}  
   end
 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-05-25T13:47:05+00:00Added an answer on May 25, 2026 at 1:47 pm

    The partial does not know about the comments because you never set them. The comments action in the controller needs to look like this:

    def comments
       @comments = Comment.find(params[:id])
       respond_to do | format |
    

    (replace params[:id] with the appropriate parameter from your route)

    You’re doing an AJAX request and since http is stateless, the comments action does not know anything about any previous requests – which means that the comments from _health.html.erb have ceased to exist for the comments action in the controller.

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

Sidebar

Related Questions

I am trying to take a PHP variable and pass it along to Flash
I'm trying to encode an image using base64 in Node.JS to pass along to
The table below works well. However, I am trying to pass $row[username] along as
I'm trying to pass one method to another in elisp, and then have that
I'm trying to pass along the question AND the id of the question in
I am trying to use window.open() to pass along some arguments to another page.
I have a Windows executable (native, not .Net) project that I'm trying to pass
MVC 3. VB.NET application.. I am trying to pass a id along to keep
using the gems cells and declarative_authorization (along with Devise) and I'm trying to figure
Now I am trying to use MPI_Sendand MPI_Recv to pass best found solutions among

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.