Skip to content

Instantly share code, notes, and snippets.

@abrambailey
abrambailey / blah
Created August 12, 2012 06:49
blah
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
belongs_to :user
attr_accessible :body, :user
validates_length_of :body, :minimum => 1
validates_presence_of :user
end
models/product.rb
def category_name category.try(:name) end def category_name=(name) self.category = Category.find_or_create_by_name(name) if name.present? end def category_name
category.try(:name)
end
def category_name=(name)
self.category = Category.find_or_create_by_name(name) if name.present?
endapp/assets/javascripts/application.js
models/product.rb
def category_name category.try(:name) end def category_name=(name) self.category = Category.find_or_create_by_name(name) if name.present? end def category_name
category.try(:name)
end
def category_name=(name)
self.category = Category.find_or_create_by_name(name) if name.present?
endapp/assets/javascripts/application.js
//= require jquery-ui //= require jquery-uiapp/assets/javascripts/products.js.coffee
jQuery -> $('#product_category_name').autocomplete source: $('#product_category_name').data('autocomplete-source') jQuery ->
@brand1 = params[:brand][:name]
@model = params[:brand][:models_attributes]["0"]["name"]
@submodel = params[:brand][:models_attributes]["0"]["submodels_attributes"]["0"]["name"]
@style = params[:brand][:models_attributes]["0"]["submodels_attributes"]["0"]["styles_attributes"]["0"]["name"]
a = Brand.find_or_create_by_name(@brand1)
b = Model.find_or_create_by_name(@model, :brand_id => a.id)
c = Submodel.find_or_create_by_name(@submodel, :model_id => b.id)
d = Style.new(:name => @style, :submodel_id => c.id)
d.save
@brand1 = params[:brand][:name]
@model = params[:brand][:models_attributes]["0"]["name"]
@submodel = params[:brand][:models_attributes]["0"]["submodels_attributes"]["0"]["name"]
@style = params[:brand][:models_attributes]["0"]["submodels_attributes"]["0"]["styles_attributes"]["0"]["name"]
a = Brand.find_or_create_by_name(@brand1)
b = Model.find_or_create_by_name(@model, :brand_id => a.id)
c = Submodel.find_or_create_by_name(@submodel, :model_id => b.id)
d = Style.new(:name => @style, :submodel_id => c.id)
d.save