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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:50:28+00:00 2026-06-14T18:50:28+00:00

I’m starting with Ruby on Rails and get’m making an application that takes the

  • 0

I’m starting with Ruby on Rails and get’m making an application that takes the likes of a facebook user and transforms them into products, creating a personalized gift list.

Well, I have three models: user, and like product. They are thus:

class Like < ActiveRecord::Base
  belongs_to :user
  has_one :product
  attr_accessible :category, :created_time, :name
end

class Product < ActiveRecord::Base
  belongs_to :user
  has_one :like
  attr_accessible :image_url, :price_max, :price_min, :product_name,
  :url
end

class User < ActiveRecord::Base
 has_many :likes, dependent: :destroy
 has_many :products, through: :likes, dependent: :destroy
 attr_accessible :email, :password, :password_confirmation, :remember_me,:first_name, :last_name, :gender, :facebook_username, :provider, :uid
end

I am also using two gems that help me catch the likes and turn them into products. I have two methods I use in ‘rails console’ for this:

#Facebook Client
client = FBGraph::Client.new(
  client_id: 'client_id',
  secret_id: 'secret_id',
  token: 'token'
  )

#Getting and Recording Likes
like = client.selection.me.likes.info!.data.data
like.sort_by{ |like| like.created_time.to_i }.reverse.each do |like|
    case like.category
      when 'Musician/band' then category = 'band'
     ...
    else next
      Like.create(category: category, created_time: like.created_time, name: like.name, user_id: current_user.id)
    end


#Product API Client
buscape = Buscape.new(
  app_id: 'app_id',
  sandbox: true
  )

#Getting product through likes, and recording
def find_for_products
likes.each do |like|
  case like.category
    when 'band' then
      product = @buscape.products.where(keyword: URI.encode(like.name), categoryId: 2921, results: 1)['product']
    ...
    else next
    end

    Product.create(
      image_url:product['thumbnail']['url'],
      price_max:product['priceMax'],
      price_min:product['priceMin'],
      product_name:product['productName'],
      url:product['links']['link'][0]['url']
      )
  end
end

Using the rails console, I can manually register products and likes using Like.new and Product.new, and assign it to a user accessing and using ‘user.products’, but I have no idea how to implement it and in my view and in my comtroller to catch the likes of current_user and produce products at the moment the user clicks a button ‘Find products for me’

Can anyone help me?

  • 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-14T18:50:30+00:00Added an answer on June 14, 2026 at 6:50 pm

    If you’re using resources, you can define a new action on User in your routes.rb file, like this:

    resources :user do
      member do
        post 'find_products'
      end
    end
    

    Then implement this action in the controller class.

    One option is to put the code you have for querying FB and finding products into a self method in the Product model, something like Product.find_and_create_products(user). Or alternatively into a separate module in a new file in lib directory in your rails app. Then call it from the controller.

    If this operation takes a long time, you can later add some additonal code to run it as a delayed job, with something like delayed_job.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am currently running into a problem where an element is coming back from

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.