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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:51:42+00:00 2026-05-16T05:51:42+00:00

I am implementing a favorites feature into a community blog application, and would like

  • 0

I am implementing a “favorites” feature into a community blog application, and would like to use Ajax.

When users like a front page post, there is a “+” symbol they can click to add that post to their collection of favorites.

The feature works great without Ajax functionality. But now I’m adding the Ajax.

In the view:

<span id="favorite_<%= entry.id %>">
  <%= link_to_remote "+",  :url => { :action => 'add_favorite' },
                           :entry => entry.id,
                           :user => session[:user_id],
                           :update => 'favorite_' + entry.id.to_s %>
</span>

The corresponding controller action:

def add_favorite
  @favorite = Favorite.new(:entry_id => :entry, :user_id => :user)
  if @favorite.save
    render :text => "added to favorites", :layout => false
  end
end

The text is rendering appropriately in the view, as though the action has worked. But when I check the list of favorites, it hasn’t been added.

I ran the line

@favorite = Favorite.new(:entry_id => :entry, :user_id => :user)

in the interactive shell and it was all good. Everything saved.

What am I overlooking/doing wrong?

  • 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-16T05:51:43+00:00Added an answer on May 16, 2026 at 5:51 am

    For some reason you’re passing in symbols instead of variables, so you’re probably getting a record with nothing assigned, and hence no association:

    @favorite = Favorite.new(:entry_id => params[:entry_id], :user_id => params[:user_id])
    

    That should handle linking the associations if you have a belongs_to defined.

    Keep in mind that :user_id is merely a symbol, nothing more, where user_id is a variable, and params[:user_id] is the parameter that may have been passed in. Symbols are often used as hash keys because they are very light-weight and easy to compare.

    For consistency’s sake, try and pass in _id type parameters with the _id at the end. In this case this would be:

    <%= link_to_remote "+",
         :url => { :action => 'add_favorite' },
         :entry_id => entry.id,
         :user_id => session[:user_id],
         :update => 'favorite_' + entry.id.to_s
    %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am in the process of implementing a favorites system into my web application.
implementing service something similar with tinyurl or bit.ly, I'm would like to expose service
I'm interested in implementing a Favorites Bar in my Cocoa application in the same
when implementing a recursive function during development, i will use a counter and exit
Implementing a custom VM and I've come to use registers (these will store pointers
Implementing a low pass FIR filter, when should one use FFT and IFFT instead
When implementing move constructors and move assignment operators, one often writes code like this:
Whilst implementing my first MVVM application in WPF, I've been wondering about the pros
Implementing Ajax requests in my rails 3 app has been one of the most
Whilst implementing the use of ODP.Net in our apps I came across a potential

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.