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

  • Home
  • SEARCH
  • 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 808689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:36:11+00:00 2026-05-15T00:36:11+00:00

I am successfully using RJS to implement AJAX on a page.replace.html create.js.rjs. I am

  • 0

I am successfully using RJS to implement AJAX on a page.replace.html create.js.rjs. I am attempting to update two locations instead of one and after watching Ryan Bates Railscast I am very close (I think) but have a problem in the syntax of my /views/likes/create.js.rjs file. Here is the situation:

located at /views/likes/create.js.rjs is the following code:

page.replace_html  "votes_#{ @site.id }", :partial => @like
page.replace_html  "counter", 10 - (@question.likes.count :conditions => {:user_id => current_user.id})
page[@like].visual_effect :highlight

My problem lies in the second line. The div “counter” displays the following code in the /views/question/show.html.erb page:

    <div id="counter">
        You have <%= 10 - (@question.likes.count :conditions => {:user_id => current_user.id}) %> votes remaining for this question
    </div>

From watching the screen cast I believe that my error has to do w/ the syntax of the second line. Specifically he mentions that you cannot use a local instance variable but not sure how to make the change. Thoughts?

UPDATE: Here is the error I am getting:

ActionView::TemplateError (undefined method `likes' for nil:NilClass) on line #2 of app/views/likes/create.js.rjs:
1: page.replace_html  "votes_#{ @site.id }", :partial => @like
2: page.replace_html  "counter", 10 - (@question.likes.count :conditions => {:user_id => current_user.id})
3: page[@like].visual_effect :highlight

    app/views/likes/create.js.rjs:2:in `_run_rjs_app47views47likes47create46js46rjs'
    app/views/likes/create.js.rjs:1:in `_run_rjs_app47views47likes47create46js46rjs'
    app/controllers/likes_controller.rb:8:in `create'

Rendered rescues/_trace (103.8ms)
Rendered rescues/_request_and_response (0.4ms)
Rendering rescues/layout (internal_server_error)

UPDATE:

class LikesController < ApplicationController

  def create
    @user = current_user
    @site = Site.find(params[:site_id])
    @like = @site.likes.create!(params[:like].merge(:user_id => @user.id))

    respond_to do |format|
     format.html { redirect_to @site}
     format.js
     end
  end
end

UPDATE: here is the likes form:

    <% remote_form_for [site, Like.new] do |f| %>
    <%= f.hidden_field :site_name, :value => "#{site.name}" %>
    <%= f.hidden_field :question_id, :value => @question.id %> 
    <%= f.hidden_field :ip_address, :value => "#{request.remote_ip}" %>
    <%= f.hidden_field :like, :value => "1" %>
    <%= submit_tag "^" , :class => 'voteup' %>
<% 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-15T00:36:12+00:00Added an answer on May 15, 2026 at 12:36 am

    Try getting @question like this,as your question_id will be present inside params[:like] hash

     @question = Question.find params[:like][:question_id]
    

    Anyway for double checking print your params like this so add a puts statement in create action of likes_controller.

    puts params.inspect,params[:like][:question_id]
    

    You have this error (undefined method `likes’ for nil:NilClass) on line #2

    Which means your @question is nil, you never declared this instance in your create action.

    Hope this works for you.

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

Sidebar

Related Questions

How do you go about checking that an IIS website is successfully using Kerberos
I have an HBITMAP containing alpha channel data. I can successfully render this using
I have been using Hibernate very successfully, but today I noticed a bizarre phenomenon
using the Code Snippet for sending email in VB.Net I have successfully sent an
I am (successfully) calling the Windows FilterSendMessage function in c# using the following pinvoke
I have set an event successfully using myEntry.setTitle(new PlainTextConstruct(TEST)) myEntry.setContent(new PlainTextConstruct(See how much text
When using the php include function the include is succesfully executed, but it is
I am using MailLogger to send a message about a failed/successful release. I would
Has someone successfully overridden the scoring of documents in a query so that the
I have successfully connected to an Oracle database (10g) from C# (Visual Studio 2008)

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.