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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:25:11+00:00 2026-05-25T20:25:11+00:00

I want to have a Resque worker get sentiment via the Viralheat API for

  • 0

I want to have a Resque worker get sentiment via the Viralheat API for tags for a brand instance
(belongs to User) in the background, and then save the mood parameter of that response to a Tag.

Update:

I’ve revised the code and now the worker fails because it says undefined method score for nil:NilClass. That’s happening because ActsAsTaggableOn::Tagging.find_by_tag_id(tag.id).score.create has no tag.id to check against, also I don’t think .create is valid Ruby.

Viralheat API response (JSON) format:

{"prob":0.537702567133646,"mood":"positive","text":"hello, goodbye"}

Controller:

def update
  @brand = Brand.find(params[:id])
  current_user.tag(@brand, :with => params[:brand][:tag_list], :on => :tags)
  if @brand.update_attributes(params[:brand])
    redirect_to :root, :notice => "Brand tagged."
  else
    render :action => 'edit'
  end
  Resque.enqueue(SentimentJob, @brand.tags)
end

sentiment_job.rb Worker:

require 'resque-retry'

class SentimentJob
  @queue = :sentiment_pull

  def self.perform(tags)

    tags.each do |tag|
    url = "http://www.viralheat.com/api/sentiment/review.json"
    @sentiment_response = url.to_uri.get(
        :api_key => 'MY KEY',
        :text => tag.name.to_s ).deserialize          

    #If I comment out the 3 lines below, the worker runs and I get 3 successful callbacks but can't save them.

    @sentiment_value = @sentiment_response[:mood]
    @sentiment_store = ActsAsTaggableOn::Tagging.find_by_tag_id(tag.id).score.create(@sentiment_value)
    @sentiment_store.save
    end
  end
end

Tagggings table:

create_table "taggings", :force => true do |t|
  t.integer "tag_id"
  t.integer "taggable_id"
  t.string "taggable_type"
  t.integer "tagger_id"
  t.string "tagger_type"
  t.string "context"
  t.datetime "created_at"
  t.string "Sentiment"
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-25T20:25:11+00:00Added an answer on May 25, 2026 at 8:25 pm

    You have a typo in your argument list: def self.perform(tag.id, user_id) should be def self.perform(tag_id, user_id) (note the underscore).

    Update

    You shouldn’t be using instance variables in a Resque Job. You are actually trying to use @brand before you declare it.

    You are trying to get information from params. There is no request, and thus no params. You probably want to swap out that find argument with the tag_id argument.

    The order you are queueing arguments is getting flipped. Your enqueue call is specifying the user_id before the tag_id. The job is expecting the tag_id before the user_id.

    And since you updated your question, you have switched the tag_id argument into tags_id. I don’t know if you realize this, but calling brand.tags.id will probably return just a single id (I’m not too familiar with acts_as_taggable).

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

Sidebar

Related Questions

i want have an image and i want to set it as a background
I have a UITextView and I want have two buttons. When the user taps
I want to have a form on my page take user input, a URL
I have a resque job that is supposed to call a third-party API. I
I have a Reporter worker for Resque in my Rails 3.2.8 application. I frequently
I have a script that retrieves some twitter usernames and I want to get
I have implemented resque queuing system in my rails app. I want to know
I want to use Resque in a Ruby on Rails application. I have no
I want to move some of my sessions controller process into a Resque worker
Using Resque and Devise, i have roles for User, like: User.first.role #=> admin User.last.role

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.