This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cake < ActiveRecord::Base | |
has_many :layers | |
end | |
class Layers < ActiveRecord::Base | |
belongs_to :cake | |
belongs_to :creation_setting, :polymorphic => true | |
end | |
class IceCreamLayerSetting < ActiveRecord::Base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create the rails project using mysql as db instead of sqlite | |
rails -d mysql ProjectName | |
#set up db | |
mysqladmin -u root create project_name_development | |
mysqladmin -u root create project_name_test | |
... | |
#Do all yer configuring stuff with for db in config/database.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
params = {:thickness => "2 inches", | |
:comments_attributes => [{:text => "the silly string"}, | |
{:text => "the silly putty"}]} | |
Layer.new(params) | |
#=> ActiveRecord::UnknownAttributeError: unknown attribute: comments_attibutes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
params = {:thickness => "4 cm", | |
:creation_setting_type => "PhylloLayerSetting", | |
:creation_setting_attributes => {:bake_time => "24 min"}} | |
Layer.new(params) | |
#=> NoMethodError: undefined method `build_creation_setting' for #<Layer:0x2420bc8> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def build_creation_settings(params) | |
type = self.attributes["creation_setting_type"] | |
#create an array with the name of all application models | |
models = [] | |
Dir.glob( RAILS_ROOT + '/app/models/*' ).each do |f| | |
models << File.basename( f ).gsub( /^(.+).rb/, '\1').camelize | |
end | |
#check to make sure that the type is actually a model before passing it | |
#through the scarriness of eval() | |
if models.include? type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attr_accessor :creation_setting_attributes | |
def comments_attributes=(attributes) | |
attributes.each { |att| self.comments.build(att) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TasksController < ApplicationController | |
def create | |
@task = Task.new(params[:task]) | |
respond_to do |format| | |
# If all is well, clear out the new_task store and redirect to the project | |
if @task.save | |
session[:new_task] = nil | |
flash[:notice] = 'Task added successfully' | |
format.html { redirect_to @task.project } | |
# If something goes south, save the task that is being worked on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(in /Users/cts/code/sharp-logic) | |
rake aborted! | |
undefined method `feature_pattern=' for #<Cucumber::Rake::Task:0x1015dbfb8> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem install cucumber -v 0.3.104 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File activerecord/lib/active_record/nested_attributes.rb, line 289 | |
def assign_nested_attributes_for_one_to_one_association(association_name, attributes) | |
options = nested_attributes_options[association_name] | |
attributes = attributes.with_indifferent_access | |
check_existing_record = (options[:update_only] || !attributes['id'].blank?) | |
if check_existing_record && (record = send(association_name)) && | |
(options[:update_only] || record.id.to_s == attributes['id'].to_s) | |
assign_to_or_mark_for_destruction(record, attributes, options[:allow_destroy]) unless call_reject_if(association_name, attributes) |
OlderNewer