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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:29:04+00:00 2026-06-10T19:29:04+00:00

I am passing a collection (@feed_items) to a _feed_item partial via the :collection option.

  • 0

I am passing a collection (@feed_items) to a _feed_item partial via the :collection option. Inside the _feed_item partial I want to render another partial _like_button. In the _like_button partial I want to be able to access a specific member of the collection. What should I be passing from the _feed_item partial to the _like_button partial?

 @feed_items = current_user.user_feed.order("id DESC").limit(5)

_feed.html.erb

 <%= render partial: 'shared/feed_item', collection: @feed_items %>

_feed_item.html.erb

 <%= render 'likes/like_button', ????? %>

_like_button.html.erb

 <% if like = current_user.likes.find_by_feed_id(feed_item.id) %>

EDIT

Passing the local variable as per the answers below worked:

 <%= render :partial => 'likes/like_button', :locals =>{:feed_item => feed_item} %>

However, after the like is submitted, I am getting a ActionView::Template::Error (undefined local variable or method 'feed_item' when it tries to render the form again through ajax. How can I pass the local variable again through the ajax call?

Controller

class LikesController < ApplicationController
  def create
    @like = Like.create(params[:like])
    @feed = @like.feed
    render :toggle
  end

  def destroy
    like = Like.find(params[:id]).destroy
    @feed = like.feed
    render :toggle
  end
end

toggle.js.erb

 $("#like").html("<%= escape_javascript render('like_button') %>");

_like_button.html.erb

 <% if like = current_user.likes.find_by_feed_id(feed_item.id) %>
  <%= form_for like, :html => { :method => :delete }, :remote => true do |f| %>
    <%= f.submit "Unlike" %>
  <% end %>
 <% else %>
  <%= form_for current_user.likes.build(:feed_id => feed_item.id), :remote => true do |f| %>
   <%= f.hidden_field :feed_id %>
   <%= f.hidden_field :user_id %>
   <%= f.submit "Like" %>
  <% end %>
 <% end %>

_feed_item.html.erb

    <div id="like">
      <%= render :partial => 'likes/like_button', :locals =>{:feed_item => feed_item} %>
    </div>
  • 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-10T19:29:06+00:00Added an answer on June 10, 2026 at 7:29 pm
     <%= render :partial => 'likes/like_button', :locals =>{:feed_item => feed_item} %>
    

    Rails has got some awesome documention http://guides.rubyonrails.org/layouts_and_rendering.html#passing-local-variables

    In toggle.js

     $("#like").html("<%= escape_javascript(render :partial => 'likes/like_button', :locals =>{:feed_item => @feed}) %>");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a simple select->option dropdown list that I am not passing
I want to display value of collection by passing their respective attribute name. @mandates
Having some trouble with R's garbage collection, when passing objects to C++. We have
I am aware of Passing a generic collection of objects to a method that
I am passing a collection to UseSimpleClass. I would like UseSimpleClass property SimpleClassColCountChecked get
I want to pass an IEnumerable collection from view to controller using JQuery from
I render a collection of backbone models in a list view, where each model
I'm implementing some code using the java.util.concurrency framework. I will be passing a collection
I'm passing form variables in a cfinvoke argument collection: <cfinvoke component=#application.componentPath#.account method=updateServices argumentcollection=#form# />
I am having array of collection of objects and i am passing this reference

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.