Rails 3.2.5 - Multi Model Nested Form, Heroku NoMethodError - ruby-on-rails-3

I have been searching high and low for answers and I'm at a standstill. Everything works on my local development environment but everythign blows up on production (Heroku). Using same database (postgres). Heroku blows up a NoMethodError even though I don't believe I'm ever sending to that method.
I have main 3 models (additional join model), one nested form that has a has_many :through submitting to all three models, and Static_Pages#signup (acting as new action) and a Subscriptions_Controller#create where the issue is happening.
Models
class Location < ActiveRecord::Base
attr_accessible :address_line_2, :city, :lat, :long, :name, :state, :street_address, :website, :zip, :phone_number, :user_id
has_many :relationships
has_many :users, :through => :relationships
end
class User < ActiveRecord::Base
has_one :subscription
has_one :plan, :through => :subscription
has_many :relationships
has_many :locations, :through => :relationships
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :first_name, :last_name, :email, :password,
:password_confirmation, :remember_me, :stripe_token,
:phone_number,:location
end
class Subscription < ActiveRecord::Base
attr_accessor :stripe_card_token
attr_accessible :card_expiration, :card_type, :card_zip,
:current_period_end, :current_period_start, :last_four,
:next_bill_on, :plan_id, :status, :stripe_customer_token,
:trial_end, :trial_start, :user_id
belongs_to :plan
belongs_to :user
end
class Relationship < ActiveRecord::Base
belongs_to :user
belongs_to :location
end
Controllers
class StaticPagesController < ApplicationController
def home
end
def signup
#user = User.new
#plan = Plan.find_by_identifier("basic_monthly")
#location = #user.locations.build
#subscription = Subscription.new
end
def thankyou
end
end
class SubscriptionsController < ApplicationController
def create
#subscription = Subscription.new params[:subscription]
#user = User.create! params[:user]
#subscription.user = #user
#user.locations << Location.create!(params[:location])
#plan = Plan.find params[:subscription][:plan_id]
if #subscription.save
redirect_to thankyou_path
else
render template: 'static_pages#signup'
end
end
end
Signup Form
<%= form_for #user, :url => subscriptions_path(#user) do |user_form| %>
First name : <%= user_form.text_field :first_name %><br />
Last name : <%= user_form.text_field :last_name %><br />
Email : <%= user_form.email_field :email %><br />
Phone Number : <%= user_form.phone_field :phone_number %><br />
Password : <%= user_form.password_field :password %><br />
Password Confirmation : <%= user_form.password_field :password_confirmation %><br />
<%= fields_for #location do |location_fields| %>
Business Name : <%= location_fields.text_field :name %><br />
Street Address : <%= location_fields.text_field :street_address %><br />
Address Line 2 : <%= location_fields.text_field :address_line_2 %><br />
City : <%= location_fields.text_field :city %><br />
State : <%= location_fields.text_field :state %><br />
Zip : <%= location_fields.text_field :zip %><br />
Website : <%= location_fields.url_field :website %><br /><br />
<% end %>
<%= fields_for #subscription do |subscription_field| %>
<%= subscription_field.hidden_field :plan_id, value: #plan.id %>
<% end %>
<%= user_form.submit "Sign up", :class => 'btn primary large' %>
<% end %>
Finally... the error thrown from Heroku logs (again, this works perfectly fine on my local machine)
Heroku Error - UPDATED
2012-08-03T21:06:30+00:00 app[web.1]: Started GET "/signup" for 72.177.139.69 at 2012-08-03 21:06:30 +0000
2012-08-03T21:06:30+00:00 app[web.1]: Processing by StaticPagesController#signup as HTML
2012-08-03T21:06:30+00:00 app[web.1]: Plan Load (1.3ms) SELECT "plans".* FROM "plans" WHERE "plans"."identifier" = 'basic_monthly' LIMIT 1
2012-08-03T21:06:30+00:00 app[web.1]: Rendered static_pages/signup.html.erb within layouts/application (8.0ms)
2012-08-03T21:06:30+00:00 app[web.1]: Rendered layouts/_shim.html.erb (0.0ms)
2012-08-03T21:06:30+00:00 app[web.1]: Rendered layouts/_navigation.html.erb (1.3ms)
2012-08-03T21:06:30+00:00 app[web.1]: Rendered layouts/_messages.html.erb (0.1ms)
2012-08-03T21:06:30+00:00 app[web.1]: Rendered layouts/_footer.html.erb (0.2ms)
2012-08-03T21:06:30+00:00 app[web.1]: Rendered layouts/_analytics.html.erb (0.0ms)
2012-08-03T21:06:30+00:00 app[web.1]: Completed 200 OK in 458ms (Views: 52.2ms | ActiveRecord: 76.5ms)
2012-08-03T21:06:30+00:00 heroku[router]: GET www.myappname.com/signup dyno=web.1 queue=0 wait=0ms service=470ms status=200 bytes=7555
2012-08-03T21:07:02+00:00 app[web.1]:
2012-08-03T21:07:02+00:00 app[web.1]:
2012-08-03T21:07:02+00:00 app[web.1]: Started POST "/subscriptions" for 72.177.139.69 at 2012-08-03 21:07:02 +0000
2012-08-03T21:07:03+00:00 app[web.1]:
2012-08-03T21:07:03+00:00 app[web.1]: NoMethodError (undefined method `name' for #<User:0x00000003f13a30>):
2012-08-03T21:07:03+00:00 app[web.1]: app/controllers/subscriptions_controller.rb:5:in `create'
2012-08-03T21:07:03+00:00 app[web.1]:
2012-08-03T21:07:03+00:00 app[web.1]:
2012-08-03T21:07:03+00:00 app[web.1]: Processing by SubscriptionsController#create as HTML
2012-08-03T21:07:03+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"ahRL7xz6NE72fxib+KxEX9BVue/NCmS1dSLXSv66alc=", "user"=>{"first_name"=>"Big", "last_name"=>"Boy", "email"=>"example#gmail.com", "phone_number"=>"123456", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "location"=>{"name"=>"Drew's American Grille", "street_address"=>"123 Physical Address", "address_line_2"=>"", "city"=>"San Antonio", "state"=>"Texas", "zip"=>"78209", "website"=>""}, "subscription"=>{"plan_id"=>"1"}, "commit"=>"Sign up"}
2012-08-03T21:07:03+00:00 app[web.1]: (0.7ms) BEGIN
2012-08-03T21:07:03+00:00 app[web.1]: User Exists (1.5ms) SELECT 1 FROM "users" WHERE "users"."email" = 'example#gmail.com' LIMIT 1
2012-08-03T21:07:03+00:00 app[web.1]: CACHE (0.0ms) SELECT 1 FROM "users" WHERE "users"."email" = 'example#gmail.com' LIMIT 1
2012-08-03T21:07:03+00:00 app[web.1]: (0.6ms) ROLLBACK
2012-08-03T21:07:03+00:00 app[web.1]: Completed 500 Internal Server Error in 100ms
2012-08-03T21:07:03+00:00 heroku[router]: POST www.myappname.com/subscriptions dyno=web.1 queue=0 wait=0ms service=134ms status=500 bytes=643
2012-08-03T21:07:03+00:00 heroku[router]: GET www.myappname.com/favicon.ico dyno=web.1 queue=0 wait=0ms service=5ms status=304 bytes=0
I can upload a schema if need be but essentially it's as follows:
Mini version of schema
users
email
first_name
last_name
phone_number
<normal devise handlers>
...
subscriptions
user_id
plan_id
...
relationships
user_id
location_id
locations (all :null => false)
name
street_address
city
state
zip
...
Also heroku run rake db:migrate doesn't work
It throws a "database configuration does not specify adapter" exception, but Heroku overwrites the database.yml file so why would this occur?
Running `rake db:migrate --trace` attached to terminal... up, run.1
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:migrate
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:schema:dump (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:schema:dump
rake aborted!
database configuration does not specify adapter
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/railties/databases.rake:356:in `block (4 levels) in <top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/railties/databases.rake:355:in `open'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/railties/databases.rake:355:in `block (3 levels) in <top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/railties/databases.rake:161:in `block (2 levels) in <top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/railties/databases.rake:156:in `block (2 levels) in <top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `load'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `<main>'
Tasks: TOP => db:schema:dump

I made a stupid silly mistake (still new at Ruby and programming in general). I had a previous model called old_user.rb that had class User < ActiveRecord::Base which conflicted with user.rb and generated out the other errors. For some reason, I guess the load order on my dev machine was different than Heroku's load order and why I never realized it.

Related

Rails seed.rb can't find table that exists in schema and SQL

Class is a reserved word, so I have changed the table name from class_assignment to cassignments to avoid any chance that that is the error causing it (despite me having class_instruction(s). I have tried plural and singular versions, and still get the error. The cassignments table is a middle table for the many to many relationship between assignments and class_instructions.
Schema :
ActiveRecord::Schema.define(:version => 20130524160107) do
create_table "assignments", :force => true do |t|
t.string "name"
t.string "fractionRepresentations"
....etc...
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "cassiggnments", :force => true do |t|
t.integer "class_instruction_id"
t.integer "assignment_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "cassiggnments", ["assignment_id"], :name => "index_class_assignment_on_assignment_id"
add_index "cassiggnments", ["class_instruction_id"], :name => "index_class_assignment_on_class_instruction_id"
create_table "class_instructions", :force => true do |t|
t.string "name"
t.datetime "time"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "person_id"
end
add_index "class_instructions", ["person_id"], :name => "index_class_instructions_on_person_id"
....etc....
end
Trying to seed the db in the seed.rb
# ClassInstruction Assignment
cia1 = Cassignment.create({ class_instruction_id: 4, assignment_id: 1 }, :without_protection => true ).save!
and I get the error:
rake aborted!
Could not find table 'cassignments'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/connection_adapters/sqlite_adapter.rb:465:in `table_structure'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/connection_adapters/sqlite_adapter.rb:346:in `columns'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `yield'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `default'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `columns'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:243:in `column_defaults'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/base.rb:479:in `initialize'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/persistence.rb:44:in `new'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/persistence.rb:44:in `create'
/Users/special/dev/SoundOfFractions/db/seeds.rb:83:in `<top (required)>'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `load'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `block in load'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `load'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.2/lib/rails/engine.rb:520:in `load_seed'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/railties/databases.rake:309:in `block (2 levels) in <top (required)>'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:205:in `block in invoke_prerequisites'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:203:in `each'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:203:in `invoke_prerequisites'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:183:in `block in invoke_with_call_chain'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/railties/databases.rake:252:in `block (2 levels) in <top (required)>'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/Users/special/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `eval'
/Users/special/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:setup => db:seed
The only strange thing is that despite my migrations, I didn't get a cassignment.rb model, so I had to manually create that (maybe I didn't use scaffold, what I am normally used to doing, but I digress). So for posterity, here is the cassignment.rb
class Cassignment < ActiveRecord::Base
belongs_to :class_instruction
belongs_to :assignment
end
naming pluralization matches other many to many relationship tables, and seed structures, but I have no clue where I am going wrong, other than the understanding that the seed file can't find the table, that does exist according to the sqlite browser, and is correctly called cassignments (plural).
You've created a table called cassiggnments with two 'g's
Is this a has_and_belongs_to_many relationship or a has_many :through relationship?
HABTM only:
In the former case you don't need the model and it's important that the table name be both of the joining table names in alphabetical order. assignments_class_instructions
In both cases, the correct approach to creating a join is to add instances of one class to instances of the other rather than creating the joins directly.
class_instruction = ClassInstruction.find(4)
class_instruction.assignments << Assignment.find(1)
Also, there is no problem with class_assignments and ClassAssignment as table and model names, so that isn't the issue.

ckeditor in Rails 3.0.9

i have my project with Rails 3.0.9 and i added the CKeditor 3.6.3, in development works fine, and in Staging in Heroku works fine too, but in Production crash the app.
This are the configuration i have to production:
config/application.rb
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
config/environments/production.rb
#config.assets.precompile += Ckeditor.assets
I have commented the line because config.assets is not available until Rails 3.1, but i don't want to upgrade Rails in this moment.
app/models/ckeditor/attachment_file.rb
class Ckeditor::AttachmentFile < Ckeditor::Asset
has_attached_file :data,
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:url => ":s3_domain_url"
validates_attachment_size :data, :less_than => 100.megabytes
validates_attachment_presence :data
def url_thumb
#url_thumb ||= Ckeditor::Utils.filethumb(filename)
end
end
app/models/ckeditor/picture.rb
class Ckeditor::Picture < Ckeditor::Asset
has_attached_file :data, :styles => { :content => '800>', :thumb => '118x100#' },
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":picture/:id/:style.:extension",
:url => ":s3_domain_url"
validates_attachment_size :data, :less_than => 2.megabytes
validates_attachment_presence :data
def url_content
url(:content)
end
end
And i received the next error:
/home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library': uninitialized constant Ckeditor::Asset (NameError)
from /home/jorge/trabajos/blanet/app/models/ckeditor/attachment_file.rb:1:in `<top (required)>'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/engine.rb:138:in `block (2 levels) in eager_load!'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/engine.rb:137:in `each'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/engine.rb:137:in `block in eager_load!'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/engine.rb:135:in `each'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/engine.rb:135:in `eager_load!'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/application.rb:108:in `eager_load!'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/application/finisher.rb:41:in `block in <module:Finisher>'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `instance_exec'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `run'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/initializable.rb:50:in `block in run_initializers'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `each'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `run_initializers'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/application.rb:134:in `initialize!'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/application.rb:77:in `method_missing'
from /home/jorge/trabajos/blanet/config/environment.rb:5:in `<top (required)>'
from /home/jorge/trabajos/blanet/config.ru:3:in `block in <main>'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/builder.rb:46:in `instance_eval'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/builder.rb:46:in `initialize'
from /home/jorge/trabajos/blanet/config.ru:1:in `new'
from /home/jorge/trabajos/blanet/config.ru:1:in `<main>'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/builder.rb:35:in `eval'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/builder.rb:35:in `parse_file'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/server.rb:162:in `app'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/server.rb:253:in `wrapped_app'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/server.rb:204:in `start'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/commands/server.rb:65:in `start'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/commands.rb:30:in `block in <top (required)>'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/commands.rb:27:in `tap'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Any one can help me?
Thanks for advance.
It looks like it can't load the parent class for your attachments. Is Ckeditor::Asset defined somewhere? Is it being loaded? Maybe you need a require ckeditor/asset somewhere?

Getting an error with custom validation in a Rails 3 ActiveModel

I'm trying to use the Date Validator Gem but I am running into an error and I'm not sure if it's because the model isn't Active Record or not (I've seen people suggest that validation is a bit funky in ActiveModel when not in ActiveRecord).
I am using Ruby 1.9.2 & Rails 3.0.7. I've attached both the class and the error below.
Thanks in advance for any help!
Class
require 'ice_cube'
require 'active_support'
require 'active_support/time_with_zone'
require 'ostruct'
require 'tzinfo'
require 'active_model'
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
class Schedule
attr_accessor :yaml, :repeat, :interval, :interval_unit, :start_time, :start_date, :end_date, :end_time, :ends, :on, :after, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday
validates_presence_of :repeat, :start_date, :start_time, :end_date, :end_time, :ends
validates_presence_of :interval, :interval_unit, :if => :ends_never?
validates_presence_of :on, :if => :ends_on_date?
validates_numericality_of :after, :greater_than => 0, :if => :ends_after_recurrences?
validates :start_date, :date => { :after => Time.now }
validates :end_date, :date => { :after => :start_date }
validates :on, :date => { :after => :end_date }
def initialize(attributes = {})
end
def persisted?
false
end
private
def parse_schedule
if :repeat == 0
get_repeatable
end
end
def parse_yaml
end
def ends_on_date?
return :ends == "on"
end
def ends_never?
return :ends == "never"
end
def ends_after_recurrences?
return :ends == "after"
end
end
Error from Rails Console
ruby-1.9.2-p180 :001 > s = Schedule.new
NoMethodError: undefined method `new' for DateValidator:Module
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/with.rb:70:in `block in validates_with'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/with.rb:69:in `each'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/with.rb:69:in `validates_with'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/validates.rb:90:in `block in validates'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/validates.rb:83:in `each'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/validates.rb:83:in `validates'
from /Users/chance/Sites/EatingNow/app/models/schedule.rb:16:in `<class:Schedule>'
from /Users/chance/Sites/EatingNow/app/models/schedule.rb:10:in `<top (required)>'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:454:in `load'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:454:in `block in load_file'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:596:in `new_constants_in'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:453:in `load_file'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:340:in `require_or_load'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:491:in `load_missing_constant'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:183:in `block in const_missing'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:181:in `each'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:181:in `const_missing'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/rspec-expectations-2.5.0/lib/rspec/expectations/backward_compatibility.rb:6:in `const_missing'
from (irb):1
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
You have included/extended the top-level namespace. Make sure the includes/extends are IN the class.
class Schedule
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming

Undefined method for friendly_id implementation

This is what my Plan.rb looks like:
class Plan < ActiveRecord::Base
has_many :users
has_friendly_id :plan, :use_slug => true
end
User.rb
class User < ActiveRecord::Base
#There is other stuff in here, but I stripped it out for brevity purposes.
has_and_belongs_to_many :projects
has_many :stages
has_many :uploads
has_many :comments
has_many :assignments
has_many :roles, :through => :assignments
belongs_to :plan
end
This is the error message I am getting:
'ruby-1.9.2-p0 > Plan.create(:name => "First_Test", :storage => "100")
NoMethodError: undefined method `plan' for #<Plan:0x00000102b8a2d8>
/gemms/ruby-1.9.2-p0/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:364:in `method_missing'
/gemms/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/attribute_methods.rb:46:in `method_missing'
/gems/ruby-1.9.2-p0/gems/friendly_id-3.2.0/lib/friendly_id/slugged.rb:82:in `slug_text'
/gems/ruby-1.9.2-p0/gems/friendly_id-3.2.0/lib/friendly_id/active_record_adapter/slugged_model.rb:49:in `build_a_slug'
/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:419:in `_run_save_callbacks'
/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/callbacks.rb:277:in `create_or_update'
/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/persistence.rb:39:in `save'
/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/validations.rb:43:in `save'
/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/attribute_methods/dirty.rb:21:in `save'
/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/transactions.rb:237:in `block (2 levels) in save'
/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/transactions.rb:289:in `block in with_transaction_returning_status'
/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/transactions.rb:204:in `transaction'
/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/transactions.rb:287:in `with_transaction_returning_status'
/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/transactions.rb:237:in `block in save'
/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/transactions.rb:248:in `rollback_active_record_state!'
/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/transactions.rb:236:in `save'
/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/base.rb:498:in `create'
from (irb):3
/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in `start'
/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in `start'
/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Not sure what I am doing wrong here, but I can't create any new 'plans'.
It looks like your database doesn't have a plan column in your plans table. In addition to adding the has_friendly_id statement to your model, did you create and run a migration to add the plan field to your database?
You can also get this error (undefined method `has_friendly_id') if you have upgraded friendly_id from Version 3 to 4.
Command 'has_friendly_id' has been replaced by 'friendly_id' - see how to upgrade here:
http://rubydoc.info/github/norman/friendly_id/master/file/WhatsNew.md
Note: You'll also need to create a migration to add a new slug column to your table.

How to properly use Factory_girl and has_many 'through' models

I'm having a little difficulty groking the call back model and methodology in Factory Girl. Using this post http://robots.thoughtbot.com/post/254496652/aint-no-calla-back-girl I started giving it a go and, now I'm erroring in the spec. I am new to Rails...so I may be missing something really fundamental.
The Error is:
Failure/Error: #user = Factory(:admin_user)
undefined method 'each' for #
The Models:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable, :lockable,
:recoverable, :rememberable, :trackable, :validatable, :token_authenticatble
# Setup accessible (or protected) attributes for your model
attr_accessible :username, :email, :role_ids, :password, :password_confirmation, :remember_me
has_many :userroles
has_many :roles, :through=>:userroles
def role?(role)
return !!self.roles.find_by_name(role.to_s.camelize)
end
end
class Role < ActiveRecord::Base
attr_accessible :name
validates :name, :presence=>true,
:length=>{:minimum=>4, :maximum=>30}
has_many :userroles
has_many :users, :through=>:userroles
end
class Userrole < ActiveRecord::Base
attr_accessible :user_id, :role_id
belongs_to :user
belongs_to :role
end
The Factories:
Factory.define :user do |f|
f.email 'someone#somecompany.com'
f.username 'foo'
f.password '123456'
end
Factory.define :role do |r|
r.name 'testrole'
end
Factory.define :userrole do |ur|
ur.association(:role)
ur.userrole{|ur| ur.userrole(:user)}
end
Factory.define :admin_role, :class => 'Role' do |userrole|
userrole.role { |role| role.association(:role, :name => "Admin") }
end
Factory.define :admin_user, :parent => :user do |user|
user.after_create { |u| Factory(:admin_role, :userroles => u) }
end
Lastly the simple spec:
require File.dirname(__FILE__) + '/../spec_helper'
describe RolesController do
fixtures :all
include Devise::TestHelpers
render_views
before (:each) do
#user = Factory(:admin_user)
sign_in #user
end
it "index action should render index template" do
get :index
response.should render_template(:index)
end
end
Update: Adding Stack Trace
ruby-1.9.2-p136 :001 > u=Factory(:admin_user)
NoMethodError: undefined method `each' for #<User:0x00000004d737d8>
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:364:in `method_missing'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/activerecord-3.0.3/lib/active_record/attribute_methods.rb:46:in `method_missing'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/activerecord-3.0.3/lib/active_record/associations/association_collection.rb:352:in `replace'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/activerecord-3.0.3/lib/active_record/associations.rb:1524:in `block in collection_accessor_methods'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl/proxy/build.rb:13:in `set'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl/factory.rb:320:in `block in run'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl/factory.rb:320:in `each'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl/factory.rb:320:in `run'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl/factory.rb:270:in `create'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl/factory.rb:301:in `default_strategy'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl.rb:20:in `Factory'
from /home/ryan/Sites/Holocron/spec/factories/users.rb:22:in `block (2 levels) in <top (required)>'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl/proxy.rb:29:in `call'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl/proxy.rb:29:in `block in run_callbacks'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl/proxy.rb:28:in `each'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl/proxy.rb:28:in `run_callbacks'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl/proxy/create.rb:7:in `result'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl/factory.rb:327:in `run'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl/factory.rb:270:in `create'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl/factory.rb:301:in `default_strategy'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/factory_girl-1.3.2/lib/factory_girl.rb:20:in `Factory'
from (irb):1
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in `start'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in `start'
from /home/ryan/.rvm/gems/ruby-1.9.2-p136#Holocron/gems/railties-3.0.3/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I believe you've confused yourself.
You've defined Factory.define :admin_role, :class => 'Role' do |userrole| as a Role but then in your factory definition you treat it like a Userrole. (BTW, Ruby conventions use underlines – so Userrole would be UserRole/user_role.)
Also, your user.after_create { |u| Factory(:admin_role, :userroles => u) } probably ought to be: user.after_create { |u| Factory(:admin_role, :userroles => [u]) } since a Role has_many :userroles.