RailsCasts Pro episodes are now free!

Learn more or hide this

Daniel Docki's Profile

GitHub User: danieldocki

Site: http://danieldocki.com/

Comments by Daniel Docki

Avatar

How do assets to work with https and http?

Avatar

me too, I'm using postgres

$ gem list pg
*** LOCAL GEMS ***
pg (0.14.0)

How I do fix that?

Avatar

The creation of the Category I need to pass the establishment_id how can I do this? being that he is not an attribute attr_accessible

ruby
class Product < ActiveRecord::Base

  validates :name, :description, :price, :category_name, presence: true
  validates :category, associated: true

  belongs_to :establishment
  has_one :item_carte
  has_one :category, through: :item_carte

  attr_accessible :name, :description, :price, :category_name
  
  def category_name
    category.try(:name)
  end
  
  def category_name=(name)
    self.category = Category.find_or_create_by_name(name) if name.present?
  end
end
ruby
class Category < ActiveRecord::Base

  validates :name, presence: true
  validates :name, uniqueness: true
  validates :products, associated: true

  belongs_to :establishment
  has_many :item_cartes
  has_many :products, through: :item_cartes

  attr_accessible :name
end