ActiveResource::ResourceNotFound: Failed. Response code = 404. Response message = Not Found - ruby-on-rails

Hi I'm working on a rails project, I updated the development database of my project recently. I had sqlite, now I have Postgres.
I have this method for my Product model:
def self.update_products!
ec_products = ElemetalCapital::Product.all
transaction do
ec_products.each do |ec_product|
product = ElemetalCapitalProduct.where(id: ec_product.id).first_or_initialize
product.spot_id = ec_product.spot
product.goldtrex_markup ||= 1 # default to a 1% markup
product.description = ec_product.description
product.metal = ec_product.metal
product.weight = ec_product.weight
product.elemetal_capital_premium = ec_product.premiumBuy
product.save!
end
end
end
Before the Postgres update, the method was working properly. However, after the update I'm getting this error, how can I fix that problem:
[2] pry(main)> Product.update_products!
(0.5ms) BEGIN
ElemetalCapitalProduct Load (0.5ms) SELECT "products".* FROM "products" WHERE "products"."type" IN ('ElemetalCapitalProduct') AND "products"."id" = $1 ORDER BY "products"."id" ASC LIMIT 1 [["id", "GKILO-OPM"]]
(0.4ms) ROLLBACK
ActiveResource::ResourceNotFound: Failed. Response code = 404. Response message = Not Found.
from /Users/enriquesalceda/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activeresource-4.0.0/lib/active_resource/connection.rb:144:in `handle_response'
Something that is very strange on the is the "products"."id" = $1, it shouldn't be $1.
This app use the API of a supplier elemetal capital, which provides the info about their products, and prices, then after a few calculations we update the shopify database.
Just for the record:
This is my entire Product model:
class Product < ActiveRecord::Base
self.primary_key = :id
monetize :elemetal_capital_premium_cents, allow_nil: true
belongs_to :spot
def to_hash
instance_variables.each_with_object({}) do |var, hash|
hash[var.to_s.delete("#")] = instance_variable_get(var)
end
end
def metal_name
case metal
when "Ag" then "Silver"
when "Au" then "Gold"
when "Pd" then "Palladium"
when "Pt" then "Platinum"
end
end
def price
# return 1300 if spot.nil?
spot_price = spot.ask
ec_price = spot_price + elemetal_capital_premium
total_price = ec_price * weight
gt_price = total_price + (goldtrex_markup / 100 * total_price)
gt_price.exchange_to(:AUD)
end
def shopify_variant_data
{
barcode: id,
price: price.to_s,
weight: weight,
weight_unit: "oz",
grams: weight * 31.1034768
}
end
before_create :shopify_create
def shopify_create
data = {
title: "#{metal_name} - #{description}",
variants: [
shopify_variant_data
]
}
sp = ShopifyAPI::Product.create(data)
self.shopify_id = sp.id
end
before_update :shopify_update
def shopify_update
sp = ShopifyAPI::Product.find(shopify_id)
variant = sp.variants.first
shopify_variant_data.each do |k, v|
instance_variable_set("##{k.to_s}".to_sym, v)
end
variant.save!
end
def self.update_products!
ec_products = ElemetalCapital::Product.all
transaction do
ec_products.each do |ec_product|
product = ElemetalCapitalProduct.where(id: ec_product.id).first_or_initialize
product.spot_id = ec_product.spot
product.goldtrex_markup ||= # default to a 1% markup
product.description = ec_product.description
product.metal = ec_product.metal
product.weight = ec_product.weight
product.elemetal_capital_premium = ec_product.premiumBuy
product.save!
end
end
end
end
This is the schema:
ActiveRecord::Schema.define(version: 20150609085027) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "deliveries", force: :cascade do |t|
t.string "receiver"
t.datetime "delivery_day"
t.string "tracking_number"
t.text "delivery_notes"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "ticket_id"
end
create_table "elemetal_capital_trades", force: :cascade do |t|
t.string "location"
t.string "currency"
t.string "side"
t.string "elemetal_capital_product_id"
t.integer "quantity"
t.string "elemetal_capital_trade_id"
t.float "price_per_unit"
t.float "weight"
t.float "price_per_weight"
t.float "price_total"
t.string "time_stamp_origin"
t.string "metal"
t.float "spot"
t.integer "line_item_id"
end
add_index "elemetal_capital_trades", ["line_item_id"], name: "index_elemetal_capital_trades_on_line_item_id", using: :btree
create_table "employees", force: :cascade do |t|
t.string "first_name"
t.string "last_name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "items", force: :cascade do |t|
t.integer "quantity"
t.string "item_description"
t.float "unit_price"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "ticket_id"
end
create_table "line_items", force: :cascade do |t|
t.integer "quantity"
t.integer "shopify_line_item_id"
t.integer "order_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "shopify_product_id", limit: 8
end
add_index "line_items", ["order_id"], name: "index_line_items_on_order_id", using: :btree
create_table "orders", force: :cascade do |t|
t.integer "order_number"
t.integer "shopify_order_id"
t.integer "total"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "payments", force: :cascade do |t|
t.datetime "value_date"
t.integer "reference_number"
t.float "contract_rate", default: 0.0
t.string "trade_notes"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "ticket_id"
t.float "usd_payment", default: 0.0
end
create_table "products", id: false, force: :cascade do |t|
t.string "id", null: false
t.string "type", null: false
t.text "description", null: false
t.decimal "weight", null: false
t.string "metal", null: false
t.string "spot_id", null: false
t.integer "elemetal_capital_premium_cents"
t.decimal "goldtrex_markup", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "shopify_id", limit: 8, null: false
end
add_index "products", ["shopify_id"], name: "index_products_on_shopify_id", unique: true, using: :btree
add_index "products", ["spot_id"], name: "index_products_on_spot_id", using: :btree
create_table "spots", id: false, force: :cascade do |t|
t.string "id", null: false
t.integer "bid_cents", null: false
t.integer "ask_cents", null: false
end
create_table "tickets", force: :cascade do |t|
t.integer "goldtrex_employee"
t.string "ticket_number"
t.datetime "elemetal_capital_order_date"
t.string "trader"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "au"
t.float "au_spot_price"
t.boolean "ag"
t.float "ag_spot_price"
t.boolean "deposit"
t.float "deposit_amount"
end
end

Rails uses ORM, which hides all logic of working with DB into nice methods. Basically that means that if you change the DB – nothing will happen, app will continue to work as expected (should mention, this statement does not applicable in any case as DBs differ, but not in this case). If you get 404 – it means item is missing in the database, nothing wrong about that.
When you said you changed DB from sqlite to Postgres – had you migrated the data? Try run ElemetalCapitalProduct.count from the console to ensure it has anything. If it does, compare data you had in sqlite and the data you receive in Postgres.

Related

SQLite3::SQLException: no such column (Ruby on Rails)

So I'm trying to use appointments gem (http://www.rubydoc.info/gems/appointments/1.3.3). I've done exactly as that document says and I keep getting the following error:
ActiveRecord::StatementInvalid in AppointmentsController#index
SQLite3::SQLException: no such column: appointments.date: SELECT "appointments".* FROM "appointments" WHERE "appointments"."date" IS NULL
app/controllers/appointments_controller.rb:6:in `index'
schema.rb
ActiveRecord::Schema.define(version: 20180402162908) do
create_table "appointments", force: :cascade do |t|
t.datetime "appointment_time"
t.integer "duration"
t.float "price"
t.integer "user_id"
t.integer "client_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "appointments", ["client_id"], name: "index_appointments_on_client_id"
add_index "appointments", ["user_id"], name: "index_appointments_on_user_id"
create_table "clients", force: :cascade do |t|
t.string "name"
t.string "phone_number"
t.string "email"
t.string "address"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "clients", ["user_id"], name: "index_clients_on_user_id"
create_table "services", force: :cascade do |t|
t.string "name"
t.string "description"
t.float "price"
t.integer "duration"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
appointments_controller.rb
class AppointmentsController < ApplicationController
def index
date_from_ajax = params[:matched_date]
reduce = Appointment.where(:date => date_from_ajax)
hour_on_date = reduce.collect {|x| x.hour}
#new_dates = hour_on_date
render :layout => false
end
def new
#appointments = Appointment.create
respond_to do |format|
format.html
format.js
end
end
def create
#appointment = Appointment.create(params[:appointments])
if #appointment.save
redirect_to new_appointment_path
else
err = ''
#appointment.errors.full_messages.each do |m|
err << m
end
redirect_to new_appointment_path, :flash => { :alert => "#{err}, please try again" }
end
end
private
def appointment_params
params.require(:appointment).permit(:date, :hour, :done)
end
end
appointments.rb
class Appointment < ActiveRecord::Base
validates :date, :presence => true
validates :hour, :presence => true,
:uniqueness => {:scope => :date}
end
Is there any chance someone could help me with this.
Thanks in advance :)
(Rails version: 4.2.6)

heroku console commands add category

I deployed my rails app to Heroku. I am trying to use the Heroku console to add categories to my app but I do not know the commands.
Controller:
class PortfolioController < ApplicationController
def index
#posts = Post.all.order("created_at DESC")
end
def about
end
def portfolio
end
def contact
end
def webapp
category = Category.find_by_category('webapp')
#posts = Post.where(category_id: category.id)
end
def art
category = Category.find_by_category('gameart')
#posts = Post.where(category_id: category.id)
end
end
Schema:
ActiveRecord::Schema.define(version: 20160910220215) do
create_table "admins", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "admins", ["email"], name: "index_admins_on_email", unique: true
add_index "admins", ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true
create_table "categories", force: :cascade do |t|
t.string "category"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "posts", force: :cascade do |t|
t.string "title"
t.text "content"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.integer "category_id"
end
end
To create a category in the rails/heroku console under your table Categories simply run:
Category.connection
Then:
Category.create(name: "NAME_OF_CATEGORY")
It will then create a category as such:
#<Category id: 1, name: "NAME_OF_CATEGORY", created_at: "2016-09-14 22:25:14", updated_at: "2016-09-14 22:25:14">

How can I compare an attribute of a instance, which is a date, to the current date?

I am trying to write a scope or a method where I take the attribute (last_eaten) of an instance (line_item) and compare it to the current date. If last_eaten has a date of 1-7 days ago, it gets put in an array that will be called last_week. If last_eaten has a date of 8-14 days ago, it gets put in an array that will be called 2_weeks_ago.
I've tried quite a few things as you can see with the commented out code and several things that I had already erased, but I can't get anything to work. I'm relatively new to rails and any help would be greatly appreciated.
Model
class LineItem < ActiveRecord::Base
belongs_to :recipe
belongs_to :recipe_collection
#scope :last_week, lambda {where("line_item.last_eaten >= ?", 7.days.ago)}
#scope :last_week, lambda { |weeks| where("last_eaten > ?", weeks) }
#scope :three_weeks, lambda { where( #line_item.last_eaten < 21.days.ago.to_date) }
##line_item = LineItem.where(last_eaten: params[:last_eaten]) -- returns nil
##line_item = LineItem.where(last_eaten: params[:last_eaten] < 21.days.ago.to_date)
#def menu
# list = []
# if LineItem.last_eaten.day.to_i > 21.days.ago.day.to_i
# LineItem.last_eaten.each do |recipe_id|
# LineItem.recipe_id << list
# end
# end
# list
#end
end
Schema
ActiveRecord::Schema.define(version: 20151229223926) do
create_table "directions", force: :cascade do |t|
t.text "step"
t.integer "recipe_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "directions", ["recipe_id"], name: "index_directions_on_recipe_id"
create_table "ingredients", force: :cascade do |t|
t.string "name"
t.integer "recipe_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "ingredients", ["recipe_id"], name: "index_ingredients_on_recipe_id"
create_table "line_items", force: :cascade do |t|
t.integer "recipe_id"
t.integer "recipe_collection_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.date "last_eaten"
end
add_index "line_items", ["recipe_collection_id"], name: "index_line_items_on_recipe_collection_id"
add_index "line_items", ["recipe_id"], name: "index_line_items_on_recipe_id"
create_table "recipe_collections", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "recipes", force: :cascade do |t|
t.string "title"
t.text "description"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
scope :last_week, lambda {where("line_item.last_eaten >= ?", 7.days.ago)}
should work...
But further reading made me realise that your table is called line_items, not line_item
When you're doing sql-snippets, you need to refer to the name of the table in SQL, rather than treating it like an individual rails object's name. This means always use the pluralised version :)

Duplicating record and it's children - but children get deleted from old record

My problem is similar to:
My cloning method is stealing the children from the original model
But I can't seem to get the solution for this to work with mine. I'm trying to create an order exchange form which involves populating the form with the old record details. So when I save the form it creates a new Order record but the children seem to get deleted from the old Order record and siphoned into the new one.
Here's the code:
def new
#old_order = Order.includes(:line_items).find(params[:id])
#order = Order.new #old_order.attributes
#order.line_items = []
#old_order.line_items.each do |old|
new = old.dup # the line_item id is set before creation.
new.order_id = #order.id
new.save!
#order.line_items << new
#old_order.line_items << old # this was to see if the old line_items would reappend to the old order. Didn't help...
end
end
def create
#order = Order.new(exchange_order_params)
if #order.save
#order.update_attributes!(stage: 2, ordered_at: Date.today)
redirect_to admin_returns_url, notice: "Order moved to 'accepted' for processing"
else
flash.now[:alert] = "Please try again"
render :action => "new"
end
end
private
def exchange_order_params
params.require(:order).permit(:id, :user_id,
line_items_attributes: [:id, :order_id, :cart_id, :quantity, :_destroy,
product_attributes: [:id, :sku, :euro_price, :sterling_price, :product_group_id, :product_size_id, :product_waistband_id]])
end
Schema.rb
create_table "orders", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "returned", default: false
t.date "date_sent"
t.date "ordered_at"
t.integer "user_id"
t.boolean "return_requested", default: false
t.integer "stage", default: 0
t.decimal "order_total", default: 0.0
t.string "transaction_secret"
t.string "token"
t.string "uuid"
t.string "currency"
t.float "discounted_by", default: 0.0
end
add_index "line_items", ["cart_id"], name: "index_line_items_on_cart_id", using: :btree
add_index "line_items", ["order_id"], name: "index_line_items_on_order_id", using: :btree
add_index "line_items", ["product_id"], name: "index_line_items_on_product_id", using: :btree
create_table "line_items", force: :cascade do |t|
t.integer "quantity"
t.integer "order_id"
t.integer "cart_id"
t.integer "product_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.float "unit_price"
t.string "currency"
end
create_table "product_groups", force: :cascade do |t|
t.string "name"
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "product_sizes", force: :cascade do |t|
t.string "specification"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "product_waistbands", force: :cascade do |t|
t.string "specification"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "products", force: :cascade do |t|
t.integer "sku"
t.integer "product_group_id"
t.integer "product_size_id"
t.integer "product_waistband_id"
t.decimal "euro_price"
t.decimal "sterling_price"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "stock_level", default: 0
end
add_index "products", ["product_group_id"], name: "index_products_on_product_group_id", using: :btree
add_index "products", ["product_size_id"], name: "index_products_on_product_size_id", using: :btree
add_index "products", ["product_waistband_id"], name: "index_products_on_product_waistband_id", using: :btree
Also in the Order model I am randomising the id before_create so that when the user submits the form, it creates a dupe copy with a different Order id. This is the same for LineItems.
Order.rb (same in LineItem.rb)
before_create :randomize_id
private
def randomize_id
begin
self.id = SecureRandom.random_number(1_000_000)
end while Order.where(id: self.id).exists?
end
My approach would be to override the ActiveRecord::Base#dup method in the Order model so that it's recursive, meaning that it also duplicates the LineItem collection:
class Order < ActiveRecord::Base
def dup
duped_order = super
duped_order.line_items = line_items.map(&:dup)
duped_order
end
end
doing it this way makes it easily testable. Now the controller becomes:
class OrderController < ApplicationController
def new
#order = Order.find(params[:id]).dup
end
def create
# not sure how your form populates the params hash
# here you need to new-up and then save the order and the line items
# with the attributes from the form
end
end
Do write tests to confirm that this is doing what you intend. This is the perfect example of where the old "fat model skinny controller" paradigm should be applied.

How to combine multiple resources into one feed?

How can we combine all these resources into one feed, with the most recent submission showing at the top?
user.rb
# Returns status feed.
def feed
following_ids = "SELECT followed_id FROM relationships
WHERE follower_id = :user_id"
Habit.where("user_id IN (#{following_ids})
OR user_id = :user_id", user_id: id)
Valuation.where("user_id IN (#{following_ids})
OR user_id = :user_id", user_id: id)
Goal.where("user_id IN (#{following_ids})
OR user_id = :user_id", user_id: id)
Quantified.where("user_id IN (#{following_ids})
OR user_id = :user_id", user_id: id)
end
schema.rb
ActiveRecord::Schema.define(version: 20150311202504) do
create_table "authentications", force: true do |t|
t.integer "user_id"
t.string "provider"
t.string "uid"
t.string "index"
t.string "create"
t.string "destroy"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "days", force: true do |t|
t.integer "level_id"
t.integer "habit_id"
t.boolean "missed", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "goals", force: true do |t|
t.string "name"
t.date "deadline"
t.boolean "accomplished"
t.text "comment"
t.boolean "private_submit"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "goals", ["user_id", "created_at"], name: "index_goals_on_user_id_and_created_at"
add_index "goals", ["user_id"], name: "index_goals_on_user_id"
create_table "habits", force: true do |t|
t.datetime "left"
t.integer "level"
t.text "committed"
t.datetime "date_started"
t.string "trigger"
t.string "target"
t.string "reward"
t.text "comment"
t.boolean "private_submit"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "habits", ["user_id", "created_at"], name: "index_habits_on_user_id_and_created_at"
add_index "habits", ["user_id"], name: "index_habits_on_user_id"
create_table "levels", force: true do |t|
t.integer "user_id"
t.integer "habit_id"
t.integer "days_needed"
t.boolean "passed", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "quantifieds", force: true do |t|
t.string "categories"
t.string "metric"
t.text "comment"
t.boolean "private_submit"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "quantifieds", ["user_id", "created_at"], name: "index_quantifieds_on_user_id_and_created_at"
add_index "quantifieds", ["user_id"], name: "index_quantifieds_on_user_id"
create_table "relationships", force: true do |t|
t.integer "follower_id"
t.integer "followed_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "relationships", ["followed_id"], name: "index_relationships_on_followed_id"
add_index "relationships", ["follower_id", "followed_id"], name: "index_relationships_on_follower_id_and_followed_id", unique: true
add_index "relationships", ["follower_id"], name: "index_relationships_on_follower_id"
create_table "results", force: true do |t|
t.integer "user_id"
t.string "result_value"
t.date "date_value"
t.integer "quantified_id"
t.boolean "good"
t.text "comment"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
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", limit: 128
t.datetime "created_at"
end
add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true
add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context"
create_table "tags", force: true do |t|
t.string "name"
t.integer "taggings_count", default: 0
end
add_index "tags", ["name"], name: "index_tags_on_name", unique: true
create_table "users", force: true do |t|
t.string "name"
t.string "email"
t.text "missed_days"
t.text "missed_levels"
t.string "provider"
t.string "uid"
t.string "oauth_token"
t.datetime "oauth_expires_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "password_digest"
t.string "remember_digest"
t.boolean "admin", default: false
t.string "activation_digest"
t.boolean "activated", default: false
t.datetime "activated_at"
t.string "reset_digest"
t.datetime "reset_sent_at"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
create_table "valuations", force: true do |t|
t.string "name"
t.text "comment"
t.boolean "private_submit"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "valuations", ["user_id", "created_at"], name: "index_valuations_on_user_id_and_created_at"
add_index "valuations", ["user_id"], name: "index_valuations_on_user_id"
end
pages_controller.rb
class PagesController < ApplicationController
def home
if logged_in?
#habits = current_user.habits.build
#valuations = current_user.valuations.build
#accomplished_goals = current_user.goals.accomplished
#unaccomplished_goals = current_user.goals.unaccomplished
#averaged_quantifieds = current_user.quantifieds.averaged
#instance_quantifieds = current_user.quantifieds.instance
#feed_items = current_user.feed.paginate(page: params[:page])
end
end
def about
end
end
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Thanks so much for your time! So far Infused's answer isn't working.
The simplest way to handle it is to combine the collections with +:
cond = ["user_id IN (#{following_ids}) OR user_id = :user_id", user_id: id]
Habit.where(cond) + Valuation.where(cond) + Goal.where(cond) + Quantified.where(cond)
As Matt Brictson mentioned in a comment, there may be a better way to aggregate the various models, but simply using + to join the collections will do the trick.

Resources