undefined method `model_name' for NilClass:Class - ruby-on-rails-3

I am having trouble with adding comments to posts in a simple blog. Using Haml, Rails 3, ActiveAdmin, and Spree.
NoMethodError in Posts#show
Showing /app/views/posts/show.html.haml where line #25 raised:
undefined method `model_name' for NilClass:Class
Extracted source (around line #25):
22: .comments
23: %h3 Leave a Reply
24: / = #comment.inspect
25: = form_for #comments do |f|
26: .row-fluid
27: = f.hidden_field :post_id
28: .row-fluid
Application Trace | Framework Trace | Full Trace
activemodel (3.2.13) lib/active_model/naming.rb:163:in `model_name_from_record_or_class'
activemodel (3.2.13) lib/active_model/naming.rb:158:in `param_key'
actionpack (3.2.13) lib/action_view/helpers/form_helper.rb:369:in `form_for'
haml (4.0.3) lib/haml/helpers/action_view_mods.rb:146:in `form_for_with_haml'
haml (4.0.3) lib/haml/helpers/action_view_xss_mods.rb:28:in `form_for_with_haml_xss'
app/views/posts/show.html.haml:25:in `block in _1d7665fe0e4edacd3f10a86fba89b0fb'
haml (4.0.3) lib/haml/helpers/action_view_mods.rb:45:in `block in capture_with_haml'
haml (4.0.3) lib/haml/helpers.rb:368:in `call'
haml (4.0.3) lib/haml/helpers.rb:368:in `block in capture_haml'
haml (4.0.3) lib/haml/helpers.rb:617:in `with_haml_buffer'
haml (4.0.3) lib/haml/helpers.rb:364:in `capture_haml'
haml (4.0.3) lib/haml/helpers/xss_mods.rb:61:in `capture_haml_with_haml_xss'
haml (4.0.3) lib/haml/helpers/action_view_mods.rb:45:in `capture_with_haml'
actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:138:in `content_for'
app/views/posts/show.html.haml:1:in `_1d7665fe0e4edacd3f10a86fba89b0fb'
actionpack (3.2.13) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.13) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.13) lib/action_view/template.rb:143:in `render'
deface (0.9.1) lib/deface/action_view_extensions.rb:37:in `render'
actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
actionpack (3.2.13) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.13) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:18:in `render'
actionpack (3.2.13) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.13) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.13) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.13) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.13) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.13) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.13) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.13) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.13) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.13) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/Users/miriam.williams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
activesupport (3.2.13) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (3.2.13) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.13) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.13) lib/active_support/callbacks.rb:425:in `_run__1713495783671643053__process_action__2295715638951091725__callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.13) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.13) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.13) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.13) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.13) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.13) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:612:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.13) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `_run__2801646708740260414__call__1745177411958485085__callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in `call'
railties (3.2.13) lib/rails/engine.rb:479:in `call'
railties (3.2.13) lib/rails/application.rb:223:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
Request
Parameters:
{"title"=>"TEST 2 Post"}
app/controllers/posts_controller.rb
class PostsController < ApplicationController
def index
if params[:search]
#posts = Post.find(
:all,
:conditions => ['text LIKE ? or title LIKE ?', "%#{params[:search]}%", "%#{params[:search]}%"], :order => "created_at DESC")
else
#posts = Post.find(:all, :order => "created_at DESC")
end
#posts_by_month = #posts.group_by { |post| post.created_at.strftime("%B %Y") }
#recent_posts = Post.order('created_at DESC').limit(5)
if params[:date]
date = Time.parse(params[:date])
date1 = date.beginning_of_month
date2 = date.end_of_month
range = date1
#posts = Post.find(
:all, :order => "created_at DESC",
:conditions => ["created_at <= ? AND created_at >= ?", date2, date1])
end
end
def show
Rails.logger.debug("My object: #{#comment.inspect}")
title = params[:title]
#post = Post.where('title' => title).first
#comment = Comment.new( :post => #post )
end
End
app/models/post.rb
class Post < ActiveRecord::Base
attr_accessible :image, :text, :title, :image_file_name
has_attached_file :image, :styles => { :thumb => "150x150>", :full => "315x250>" }
has_many :comments, :dependent => :destroy
end
app/controller/comments_controller.rb
class CommentsController < ApplicationController
def create
#comment = Comment.new(params[:comment])
if #comment.save
flash[:notice] = 'Comment was successfully created.'
redirect_to(#comment.post)
else
flash[:notice] = "Error creating comment: #{#comment.errors}"
redirect_to(#comment.post)
end
end
def new
#post = Post.find(params[:post_id])
end
End
app/models/comment.rb
class Comment < ActiveRecord::Base
belongs_to :post
attr_accessible :comment, :email, :name, :website
validates :name,:email, :comment, :presence => true
validates :name, length: 2..20
End
routes.rb
devise_for :admin_users, ActiveAdmin::Devise.config
# This line mounts Spree's routes at the root of your application.
# This means, any requests to URLs such as /products, will go to Spree::ProductsController.
# If you would like to change where this engine is mounted, simply change the :at option to something different.
#
# We ask that you don't use the :as option here, as Spree relies on it being the default of "spree"
mount Spree::Core::Engine, :at => '/products'
root :to => 'pages#index'
get "history" => 'pages#history', :as => :history
get 'about' => 'pages#about', :as => :about
get 'pajama' => 'pages#pajama', :as => :pajama
get 'comfort' => 'pages#comfort', :as => :comfort
get 'contact' => 'pages#contact', :as => :contact
get 'cookbook' => 'pages#cookbook', :as => :cookbook
get 'charity' => 'pages#charity', :as => :charity
get 'retailers' => 'pages#retailers', :as => :retailers
get 'media' => 'pages#media', :as => :media
get 'official-rules' => 'pages#official_rules', :as => :official_rules
get 'terms-privacy' => 'pages#terms_privacy', :as => :terms_privacy
get "posts/archives" => 'posts#show', :as => :archives
match "posts/archives/:year/:month" => "posts#archives", :constraints => { :year => /\d{4}/, :month => /\d{2}/}
post 'messages' => 'messages#create', :as => :messages
resources :posts do
resources :comments
end
ActiveAdmin.routes(self)
End
App/views/show.html.haml
.row-fluid
.comments
%h3 Leave a Reply
/ = #comment.inspect
= form_for #comment do |f|
.row-fluid
= f.hidden_field :post
.row-fluid
= label_tag(:name, "Name", :id => 'name-label')
= f.text_field :name
.row-fluid
= label_tag(:email, "Email", :id => 'email-label')
= f.text_field :email
.row-fluid
= label_tag(:website, "Website", :id => 'website-label')
= f.text_field :website
.row-fluid
= label_tag(:comment, "Comment", :id => 'comment-label')
= f.text_area :comment
.row-fluid.submit
= f.submit("Post Comment", :id => "submit")

You're calling form_for with #comments
22: .comments
23: %h3 Leave a Reply
24: / = #comment.inspect
25: = form_for #comments do |f|
26: .row-fluid
27: = f.hidden_field :post_id
28: .row-fluid
, you have not instantiated it in the controller action
def show
Rails.logger.debug("My object: #{#comment.inspect}")
title = params[:title]
#post = Post.where('title' => title).first
#comment = Comment.new( :post => #post ) end

Related

Uninitialized constant error constant Skill:Description

I am trying to make a form and submit a skill and description into a database. I am almost done however I am getting this error after submitting my info:
NameError in SkillsController#create
uninitialized constant Skill::Description
and it points to this action in my controller:
def create
#skills = Skill.new(skill_params)
if #skills.save
redirect_to :action => 'index'
else
#skills = Skill.find(:all)
render :action => 'new'
end
end
I have a private method at the bottom defining params which states:
private
def skill_params
params.require(:skill).permit(:description)
end
This is the fullstack trace:
activerecord (4.1.2.rc1) lib/active_record/inheritance.rb:133:in `compute_type'
activerecord (4.1.2.rc1) lib/active_record/reflection.rb:221:in `klass'
activerecord (4.1.2.rc1) lib/active_record/associations/association.rb:214:in `raise_on_type_mismatch!'
activerecord (4.1.2.rc1) lib/active_record/associations/collection_association.rb:356:in `block in replace'
activerecord (4.1.2.rc1) lib/active_record/associations/collection_association.rb:356:in `each_char'
activerecord (4.1.2.rc1) lib/active_record/associations/collection_association.rb:356:in `replace'
activerecord (4.1.2.rc1) lib/active_record/associations/collection_association.rb:41:in `writer'
activerecord (4.1.2.rc1) lib/active_record/associations/builder/association.rb:118:in `description='
activerecord (4.1.2.rc1) lib/active_record/attribute_assignment.rb:45:in `public_send'
activerecord (4.1.2.rc1) lib/active_record/attribute_assignment.rb:45:in `_assign_attribute'
activerecord (4.1.2.rc1) lib/active_record/attribute_assignment.rb:32:in `block in assign_attributes'
activerecord (4.1.2.rc1) lib/active_record/attribute_assignment.rb:26:in `each'
activerecord (4.1.2.rc1) lib/active_record/attribute_assignment.rb:26:in `assign_attributes'
activerecord (4.1.2.rc1) lib/active_record/core.rb:455:in `init_attributes'
activerecord (4.1.2.rc1) lib/active_record/core.rb:198:in `initialize'
activerecord (4.1.2.rc1) lib/active_record/inheritance.rb:30:in `new'
activerecord (4.1.2.rc1) lib/active_record/inheritance.rb:30:in `new'
app/controllers/skills_controller.rb:29:in `create'
actionpack (4.1.2.rc1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.1.2.rc1) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.1.2.rc1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.1.2.rc1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.1.2.rc1) lib/active_support/callbacks.rb:113:in `call'
activesupport (4.1.2.rc1) lib/active_support/callbacks.rb:113:in `call'
activesupport (4.1.2.rc1) lib/active_support/callbacks.rb:229:in `block in halting'
activesupport (4.1.2.rc1) lib/active_support/callbacks.rb:229:in `call'
activesupport (4.1.2.rc1) lib/active_support/callbacks.rb:229:in `block in halting'
activesupport (4.1.2.rc1) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.2.rc1) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.2.rc1) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.2.rc1) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.2.rc1) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.2.rc1) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.2.rc1) lib/active_support/callbacks.rb:86:in `call'
activesupport (4.1.2.rc1) lib/active_support/callbacks.rb:86:in `run_callbacks'
actionpack (4.1.2.rc1) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.1.2.rc1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.1.2.rc1) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.1.2.rc1) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.1.2.rc1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.1.2.rc1) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.1.2.rc1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.1.2.rc1) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.1.2.rc1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.1.2.rc1) lib/abstract_controller/base.rb:136:in `process'
actionview (4.1.2.rc1) lib/action_view/rendering.rb:30:in `process'
actionpack (4.1.2.rc1) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.1.2.rc1) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.1.2.rc1) lib/action_controller/metal.rb:232:in `block in action'
actionpack (4.1.2.rc1) lib/action_dispatch/routing/route_set.rb:82:in `call'
actionpack (4.1.2.rc1) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
actionpack (4.1.2.rc1) lib/action_dispatch/routing/route_set.rb:50:in `call'
actionpack (4.1.2.rc1) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.1.2.rc1) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.1.2.rc1) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.1.2.rc1) lib/action_dispatch/routing/route_set.rb:678:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.1.2.rc1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.1.2.rc1) lib/action_dispatch/middleware/flash.rb:254:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.1.2.rc1) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.1.2.rc1) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.1.2.rc1) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
activerecord (4.1.2.rc1) lib/active_record/migration.rb:380:in `call'
actionpack (4.1.2.rc1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.2.rc1) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.2.rc1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.2.rc1) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.2.rc1) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.1.2.rc1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.1.2.rc1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.2.rc1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.2.rc1) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.2.rc1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.2.rc1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.2.rc1) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.2.rc1) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.2.rc1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.2.rc1) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.1.2.rc1) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.1.2.rc1) lib/rails/engine.rb:514:in `call'
railties (4.1.2.rc1) lib/rails/application.rb:144:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
and this is my schema:
create_table "skills", force: true do |t|
t.datetime "created_at"
t.string "description"
end
This is my skills/new.html.erb form:
<h1>Add new Skill</h1>
<%= form_tag ({action: "create"}) do %>
<p><label for="skill">Skill</label>:
<%= text_field 'skill', 'title' %></p>
<p><label for="skill_description">Description</label><br/>
<%= text_area 'skill', 'description' %></p>
<%= submit_tag "Create" %>
<% end %>
<%= link_to 'Back', {:action => 'index'} %>
I hope I have provided enough info to solve the issue and thank you anyone who knows what to do to initialize description. Thanks again and cheers!
index.html.erb:
<% if #skills.blank? %>
<p>There are not any skills currently saved in the system.</p>
<% else %>
<p>These are the current skills saved in our system</p>
<ul id="skills">
<% #skills.each do |c| %>
<li><%= link_to c.title, {:action => 'show', :id => c.id} -%></li>
<li>
<%= link_to c.title, {:action => 'show', :id => c.id} -%>
<b> <%= link_to 'Edit', {:action => 'edit', :id => c.id} %></b>
<b> <%= link_to "Delete", {:action => 'delete', :id => c.id},
:confirm => "Are you sure you want to delete this skill??" %></b>
</li>
<% end %>
</ul>
<p><%= link_to "Add new Skill", {:action => 'new' }%></p>
<% end %>
I do not have a title param available and it is causing problems.
skill.rb:
class Skill < ActiveRecord::Base
has_many :skill
has_many :description
end
hope this new info helps! Thanks again for taking a look with me.
Change the model skill.rb to this:
class Skill < ActiveRecord::Base
end
The has_many method is used to define Relations in the ORM context. There is no need to define the columns of the table itself. Rails get that information by itself.
You also have other issues in your index.html.erb and new.html.erb pages. You are referring to a title property of skill, but your migration does not show a title property.
I would recommend you delete controller, model, views, migration and data table itself (assuming that it is just a development project) and use scaffold to generate them using the command below:
$ bin/rails generate scaffold Skill title:string description:text
Please note that $ is not part of the command, its the prompt in your terminal.
Read up more on rails command line here
I think you'd better use form_for. There are no skill_params returning if you build the form that way.
form_tag is better for no model forms.
Try like this:
# skills_controller
def new
#skill = Skill.new
end
# new.html.erb
<%= form_for #skill do |f| %>
<%= f.text_area :description %>
# Other fields and tags...
<%= f.submit %>
<% end %>
Hope this helps.

Rails 3.2.17 NoMethodError in VideosController#create

I'm new to Ruby on Rails and trying to create a relatively simple web application by following this guide: http://www.sitepoint.com/youtube-rails/. I've come to a point where all the code is in place but still getting the NoMethodError in VideosController#create:
undefined method `uid=' for #<Video:0x007fb066c41d28>
app/controllers/videos_controller.rb
class VideosController < ApplicationController
def index
#videos = Video.order('created_at DESC')
end
def new
#video = Video.new
end
def create
#video = Video.new(params[:video])
if #video.save
flash[:success] = 'Video added!'
redirect_to root_url
else
render 'new'
end
end
end
app/models/video.rb
class Video < ActiveRecord::Base
attr_accessible :link
YT_LINK_FORMAT = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/i
validates :link, presence: true, format: YT_LINK_FORMAT
before_create -> do
uid = link.match(YT_LINK_FORMAT)
self.uid = uid[2] if uid && uid[2]
if self.uid.to_s.length != 11
self.errors.add(:link, 'is invalid.')
false
elsif Video.where(uid: self.uid).any?
self.errors.add(:link, 'is not unique.')
false
else
get_additional_info
end
end
private
def get_additional_info
begin
client = YouTubeIt::OAuth2Client.new(dev_key: '<my_dev_key>')
video = client.video_by(uid)
self.title = video.title
self.duration = parse_duration(video.duration)
self.author = video.author.name
self.likes = video.rating.likes
self.dislikes = video.rating.dislikes
rescue
self.title = '' ; self.duration = '00.00.00' ; self.author = '' ; self.likes = 0 ; self.dislikes = 0
end
end
def parse_duration(d)
hr = (d / 3600).floor
min = ((d - (hr * 3600)) / 60).floor
sec = (d - (hr * 3600) - (min * 60)).floor
hr = '0' + hr.to_s if hr.to_i < 10
min = '0' + min.to_s if min.to_i < 10
sec = '0' + sec.to_s if sec.to_i < 10
hr.to_s + ':' + min.to_s + ':' + sec.to_s
end
end
Full Trace
activemodel (3.2.17) lib/active_model/attribute_methods.rb:407:in `method_missing'
activerecord (3.2.17) lib/active_record/attribute_methods.rb:149:in `method_missing'
app/models/video.rb:10:in `block in <class:Video>'
activesupport (3.2.17) lib/active_support/callbacks.rb:407:in `_run__3695319422649908747__create__1619689881822406221__callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.17) lib/active_support/callbacks.rb:385:in `_run_create_callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:81:in `run_callbacks'
activerecord (3.2.17) lib/active_record/callbacks.rb:268:in `create'
activerecord (3.2.17) lib/active_record/persistence.rb:348:in `create_or_update'
activerecord (3.2.17) lib/active_record/callbacks.rb:264:in `block in create_or_update'
activesupport (3.2.17) lib/active_support/callbacks.rb:403:in `_run__3695319422649908747__save__1619689881822406221__callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.17) lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:81:in `run_callbacks'
activerecord (3.2.17) lib/active_record/callbacks.rb:264:in `create_or_update'
activerecord (3.2.17) lib/active_record/persistence.rb:84:in `save'
activerecord (3.2.17) lib/active_record/validations.rb:50:in `save'
activerecord (3.2.17) lib/active_record/attribute_methods/dirty.rb:22:in `save'
activerecord (3.2.17) lib/active_record/transactions.rb:259:in `block (2 levels) in save'
activerecord (3.2.17) lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
activerecord (3.2.17) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
activerecord (3.2.17) lib/active_record/transactions.rb:208:in `transaction'
activerecord (3.2.17) lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
activerecord (3.2.17) lib/active_record/transactions.rb:259:in `block in save'
activerecord (3.2.17) lib/active_record/transactions.rb:270:in `rollback_active_record_state!'
activerecord (3.2.17) lib/active_record/transactions.rb:258:in `save'
app/controllers/videos_controller.rb:12:in `create'
actionpack (3.2.17) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.17) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.17) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.17) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.17) lib/active_support/callbacks.rb:414:in `_run__333554687839828986__process_action__1999722818964258122__callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.17) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.17) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.17) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.17) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.17) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.17) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.17) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.17) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.17) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.17) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.17) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.17) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.17) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.17) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.17) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.17) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.17) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.17) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.17) lib/action_dispatch/routing/route_set.rb:608:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.17) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.17) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.17) lib/active_support/callbacks.rb:405:in `_run__469011070482330715__call__1619689881822406221__callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.17) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.17) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.17) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.17) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.17) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.17) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.17) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.17) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/static.rb:63:in `call'
railties (3.2.17) lib/rails/engine.rb:484:in `call'
railties (3.2.17) lib/rails/application.rb:231:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.17) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/Users/<User_Name>/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/Kappe/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/Kappe/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
I hope I've given enough information. I think something is going on in video.rb where uid and self.uid are set but I don't have enough knowledge to solve this problem. Can you help me with this? Thanks in advance!
undefined method `uid=' for #
The error is because there is no uid attribute in videos table.
You should add that attribute through migration
AddUidToVideo uid:string
this will create a migration file for adding a uid column to that table then
do rake db:migrate

Devise + OmniAuth NoMethodError UndefinedMethod Username

I'm following through Railscast #235 "Devise + OmniAuth Revised" and have run into a NoMethodError for Username whenever I try to authenticate using Twitter. I'm running Rails 3.2.
Specifically, it reads:
NoMethodError in OmniauthCallbacksController#twitter
undefined method `username' for #<User:0x007fa4744561c0>
app/models/user.rb:11:in `from_omniauth'
app/controllers/omniauth_callbacks_controller.rb:3:in `all'
I'm new to Rails, so any help would be much appreciated. Here's a look at my code:
The omniauth_callbacks_controller:
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def all
user = User.from_omniauth(request.env["omniauth.auth"])
if user.persisted?
flash.notice = "Signed in!"
sign_in_and_redirect user
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
alias_method :twitter, :all
end
The user model:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :omniauthable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me, :username
validates_presence_of :username
validates_uniqueness_of :username
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.username = auth.info.nickname
end
end
def self.new_with_session(params, session)
if session["devise.user_attributes"]
new(session["devise.user_attributes"], without_protection: true) do |user|
user.attributes = params
user.valid?
end
else
super
end
end
def password_required?
super && provider.blank?
end
def update_with_password(params, *options)
if encrypted_password.blank?
update_attributes(params, *options)
else
super
end
end
end
Framework Trace:
activemodel (3.2.8) lib/active_model/attribute_methods.rb:407:in `method_missing'
activerecord (3.2.8) lib/active_record/attribute_methods.rb:149:in `method_missing'
activemodel (3.2.8) lib/active_model/errors.rb:254:in `block in add_on_blank'
activemodel (3.2.8) lib/active_model/errors.rb:253:in `each'
activemodel (3.2.8) lib/active_model/errors.rb:253:in `add_on_blank'
activemodel (3.2.8) lib/active_model/validations/presence.rb:8:in `validate'
activesupport (3.2.8) lib/active_support/callbacks.rb:310:in `_callback_before_35'
activesupport (3.2.8) lib/active_support/callbacks.rb:473:in `_run__3967236747236009763__validate__2888041296400006394__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_validate_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
activemodel (3.2.8) lib/active_model/validations.rb:227:in `run_validations!'
activemodel (3.2.8) lib/active_model/validations/callbacks.rb:53:in `block in run_validations!'
activesupport (3.2.8) lib/active_support/callbacks.rb:425:in `_run__3967236747236009763__validation__2888041296400006394__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_validation_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
activemodel (3.2.8) lib/active_model/validations/callbacks.rb:53:in `run_validations!'
activemodel (3.2.8) lib/active_model/validations.rb:194:in `valid?'
activerecord (3.2.8) lib/active_record/validations.rb:69:in `valid?'
activerecord (3.2.8) lib/active_record/validations.rb:77:in `perform_validations'
activerecord (3.2.8) lib/active_record/validations.rb:50:in `save'
activerecord (3.2.8) lib/active_record/attribute_methods/dirty.rb:22:in `save'
activerecord (3.2.8) lib/active_record/transactions.rb:241:in `block (2 levels) in save'
activerecord (3.2.8) lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
activerecord (3.2.8) lib/active_record/transactions.rb:208:in `transaction'
activerecord (3.2.8) lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
activerecord (3.2.8) lib/active_record/transactions.rb:241:in `block in save'
activerecord (3.2.8) lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
activerecord (3.2.8) lib/active_record/transactions.rb:240:in `save'
activerecord (3.2.8) lib/active_record/persistence.rb:45:in `create'
activerecord (3.2.8) lib/active_record/relation.rb:87:in `block in create'
activerecord (3.2.8) lib/active_record/relation.rb:241:in `block in scoping'
activerecord (3.2.8) lib/active_record/scoping.rb:98:in `with_scope'
activerecord (3.2.8) lib/active_record/relation.rb:241:in `scoping'
activerecord (3.2.8) lib/active_record/relation.rb:87:in `create'
activerecord (3.2.8) lib/active_record/relation.rb:119:in `first_or_create'
actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.8) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.8) lib/active_support/callbacks.rb:436:in `_run__3199821227742357635__process_action__2555454004410598156__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.8) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.8) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.8) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.8) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.8) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.8) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.8) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.8) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.8) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.8) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:36:in `call'
actionpack (3.2.8) lib/action_dispatch/routing/mapper.rb:42:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:600:in `call'
omniauth (1.1.1) lib/omniauth/strategy.rb:394:in `call_app!'
omniauth (1.1.1) lib/omniauth/strategy.rb:356:in `callback_phase'
omniauth-oauth (1.0.1) lib/omniauth/strategies/oauth.rb:58:in `callback_phase'
omniauth (1.1.1) lib/omniauth/strategy.rb:219:in `callback_call'
omniauth (1.1.1) lib/omniauth/strategy.rb:175:in `call!'
omniauth (1.1.1) lib/omniauth/strategy.rb:157:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
warden (1.2.1) lib/warden/manager.rb:34:in `catch'
warden (1.2.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/cookies.rb:339:in `call'
activerecord (3.2.8) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `_run__635784344197953786__call__2888041296400006394__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.8) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.8) lib/rails/engine.rb:479:in `call'
railties (3.2.8) lib/rails/application.rb:223:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.8) lib/rails/rack/log_tailer.rb:17:in `call'
thin (1.4.1) lib/thin/connection.rb:80:in `block in pre_process'
thin (1.4.1) lib/thin/connection.rb:78:in `catch'
thin (1.4.1) lib/thin/connection.rb:78:in `pre_process'
thin (1.4.1) lib/thin/connection.rb:53:in `process'
thin (1.4.1) lib/thin/connection.rb:38:in `receive_data'
eventmachine (1.0.0) lib/eventmachine.rb:187:in `run_machine'
eventmachine (1.0.0) lib/eventmachine.rb:187:in `run'
thin (1.4.1) lib/thin/backends/base.rb:63:in `start'
thin (1.4.1) lib/thin/server.rb:159:in `start'
rack (1.4.1) lib/rack/handler/thin.rb:13:in `run'
rack (1.4.1) lib/rack/server.rb:265:in `start'
railties (3.2.8) lib/rails/commands/server.rb:70:in `start'
railties (3.2.8) lib/rails/commands.rb:55:in `block in <top (required)>'
railties (3.2.8) lib/rails/commands.rb:50:in `tap'
railties (3.2.8) lib/rails/commands.rb:50:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'
You need to add a username column to your users table.

Rails 3 form_for Argument Error (1 for 0) but it *must* have at least one argument, no?

I just can't seem to figure this one out...
As far as I know, you have to provide an instance variable to the form_for view helper, but it raises an error when I do that...
For a simple scaffold form_for I get an argument error wrong number of arguments (1 for 0) when supplying the instance of the model on a new action.
The relevan code:
Controller
class AdminMessagesController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource
def new
#admin_message = AdminMessage.new
logger.debug instance_variables
respond_to do |format|
format.html # new.html.erb
format.json { render json: #admin_message }
end
end
Controller instance_variables
[:#_routes, :#_action_has_layout, :#_view_context_class, :#_headers, :#_status, :#_request, :#_response, :#_env, :#_prefixes, :#_lookup_context, :#_action_name, :#_response_body, :#_config, :#_params, :#current_user, :#current_ability, :#admin_message, :#_authorized]
Model
class AdminMessage < ActiveRecord::Base
validates_presence_of :subject, :body
end
Roles (CanCan)
class Ability
include CanCan::Ability
def initialize(user)
# Define abilities for the passed in user here. For example:
user ||= User.new # guest user (not logged in)
if user.admin?
can :manage, :all
elsif user
can :manage, [Profile, BackgroundImage], :user_id => user.id
can :manage, Page, :profile => { :user_id => user.id }
can :read, [Profile]
else
can :read, [Profile]
end
New View
- #title = "New Message"
= link_to 'Back', admin_messages_path, class: 'button'
%hr
%h1= #title
= render 'form'
Form View
= form_for #admin_message do |f|
-if #admin_message.errors.any?
#error_explanation
%h2= "#{pluralize(#admin_message.errors.count, "error")} prohibited this admin_message from being saved:"
%ul
- #admin_message.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :subject
= f.text_field :subject
.field
= f.label :body
= f.text_area :body
.field
= f.label :send
= f.check_box :send
.actions
= f.submit 'Save'
Routes
resources :admin_messages
Stack Trace
ArgumentError in Admin_messages#new
Showing /example/app/views/admin_messages/_form.html.haml where line #4 raised:
wrong number of arguments (1 for 0)
Extracted source (around line #4):
1: -# - puts self.public_methods
2: -# - puts self.instance_variables
3:
4: = form_for #admin_message do |f|
5: -if #admin_message.errors.any?
6: #error_explanation
7: %h2= "#{pluralize(#admin_message.errors.count, "error")} prohibited this admin_message from being saved:"
Full Stack Trace
activerecord (3.1.2) lib/active_record/attribute_methods/read.rb:89:in `_send'
activerecord (3.1.2) lib/active_record/attribute_methods/primary_key.rb:8:in `to_key'
actionpack (3.1.2) lib/action_controller/record_identifier.rb:76:in `record_key_for_dom_id'
actionpack (3.1.2) lib/action_controller/record_identifier.rb:57:in `dom_id'
actionpack (3.1.2) lib/action_view/helpers/form_helper.rb:388:in `apply_form_for_options!'
actionpack (3.1.2) lib/action_view/helpers/form_helper.rb:365:in `form_for'
haml (3.1.3) lib/haml/helpers/action_view_mods.rb:182:in `form_for_with_haml'
haml (3.1.3) lib/haml/helpers/xss_mods.rb:132:in `form_for_with_haml_xss'
app/views/admin_messages/_form.html.haml:4:in `_app_views_admin_messages__form_html_haml__1654301332507974170_70145208768920'
actionpack (3.1.2) lib/action_view/template.rb:171:in `block in render'
activesupport (3.1.2) lib/active_support/notifications.rb:55:in `instrument'
actionpack (3.1.2) lib/action_view/template.rb:169:in `render'
actionpack (3.1.2) lib/action_view/renderer/partial_renderer.rb:256:in `render_partial'
actionpack (3.1.2) lib/action_view/renderer/partial_renderer.rb:228:in `block (2 levels) in render'
actionpack (3.1.2) lib/action_view/renderer/abstract_renderer.rb:33:in `block in instrument'
activesupport (3.1.2) lib/active_support/notifications.rb:53:in `block in instrument'
activesupport (3.1.2) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.1.2) lib/active_support/notifications.rb:53:in `instrument'
actionpack (3.1.2) lib/action_view/renderer/abstract_renderer.rb:33:in `instrument'
actionpack (3.1.2) lib/action_view/renderer/partial_renderer.rb:227:in `block in render'
actionpack (3.1.2) lib/action_view/renderer/abstract_renderer.rb:22:in `wrap_formats'
actionpack (3.1.2) lib/action_view/renderer/partial_renderer.rb:219:in `render'
actionpack (3.1.2) lib/action_view/renderer/renderer.rb:41:in `render_partial'
actionpack (3.1.2) lib/action_view/helpers/rendering_helper.rb:27:in `render'
haml (3.1.3) lib/haml/helpers/action_view_mods.rb:11:in `block in render_with_haml'
haml (3.1.3) lib/haml/helpers.rb:90:in `non_haml'
haml (3.1.3) lib/haml/helpers/action_view_mods.rb:11:in `render_with_haml'
app/views/admin_messages/new.html.haml:6:in `_app_views_admin_messages_new_html_haml__1382734216418550338_70145179834340'
actionpack (3.1.2) lib/action_view/template.rb:171:in `block in render'
activesupport (3.1.2) lib/active_support/notifications.rb:55:in `instrument'
actionpack (3.1.2) lib/action_view/template.rb:169:in `render'
actionpack (3.1.2) lib/action_view/renderer/template_renderer.rb:40:in `block (2 levels) in render_template'
actionpack (3.1.2) lib/action_view/renderer/abstract_renderer.rb:33:in `block in instrument'
activesupport (3.1.2) lib/active_support/notifications.rb:53:in `block in instrument'
activesupport (3.1.2) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.1.2) lib/active_support/notifications.rb:53:in `instrument'
actionpack (3.1.2) lib/action_view/renderer/abstract_renderer.rb:33:in `instrument'
actionpack (3.1.2) lib/action_view/renderer/template_renderer.rb:39:in `block in render_template'
actionpack (3.1.2) lib/action_view/renderer/template_renderer.rb:47:in `render_with_layout'
actionpack (3.1.2) lib/action_view/renderer/template_renderer.rb:38:in `render_template'
actionpack (3.1.2) lib/action_view/renderer/template_renderer.rb:12:in `block in render'
actionpack (3.1.2) lib/action_view/renderer/abstract_renderer.rb:22:in `wrap_formats'
actionpack (3.1.2) lib/action_view/renderer/template_renderer.rb:9:in `render'
actionpack (3.1.2) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.1.2) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.1.2) lib/abstract_controller/rendering.rb:120:in `_render_template'
actionpack (3.1.2) lib/action_controller/metal/streaming.rb:250:in `_render_template'
actionpack (3.1.2) lib/abstract_controller/rendering.rb:114:in `render_to_body'
actionpack (3.1.2) lib/action_controller/metal/renderers.rb:30:in `render_to_body'
actionpack (3.1.2) lib/action_controller/metal/compatibility.rb:43:in `render_to_body'
actionpack (3.1.2) lib/abstract_controller/rendering.rb:99:in `render'
actionpack (3.1.2) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.1.2) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.1.2) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/Users/victorstan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
activesupport (3.1.2) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.1.2) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.1.2) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.1.2) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.1.2) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.1.2) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.1.2) lib/action_controller/metal/mime_responds.rb:268:in `block in retrieve_response_from_mimes'
actionpack (3.1.2) lib/action_controller/metal/mime_responds.rb:195:in `call'
actionpack (3.1.2) lib/action_controller/metal/mime_responds.rb:195:in `respond_to'
app/controllers/admin_messages_controller.rb:33:in `new'
actionpack (3.1.2) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.1.2) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.1.2) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.1.2) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.1.2) lib/active_support/callbacks.rb:434:in `_run__1801240210143518790__process_action__2938188811796736454__callbacks'
activesupport (3.1.2) lib/active_support/callbacks.rb:386:in `_run_process_action_callbacks'
activesupport (3.1.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.2) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.1.2) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.1.2) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.1.2) lib/active_support/notifications.rb:53:in `block in instrument'
activesupport (3.1.2) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.1.2) lib/active_support/notifications.rb:53:in `instrument'
actionpack (3.1.2) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.1.2) lib/action_controller/metal/params_wrapper.rb:201:in `process_action'
activerecord (3.1.2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.1.2) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.1.2) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.1.2) lib/action_controller/metal.rb:193:in `dispatch'
actionpack (3.1.2) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.1.2) lib/action_controller/metal.rb:236:in `block in action'
actionpack (3.1.2) lib/action_dispatch/routing/route_set.rb:65:in `call'
actionpack (3.1.2) lib/action_dispatch/routing/route_set.rb:65:in `dispatch'
actionpack (3.1.2) lib/action_dispatch/routing/route_set.rb:29:in `call'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:in `block in call'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in `block in recognize'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:82:in `optimized_each'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call'
actionpack (3.1.2) lib/action_dispatch/routing/route_set.rb:532:in `call'
sass (3.1.10) lib/sass/plugin/rack.rb:54:in `call'
warden (1.1.0) lib/warden/manager.rb:35:in `block in call'
warden (1.1.0) lib/warden/manager.rb:34:in `catch'
warden (1.1.0) lib/warden/manager.rb:34:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.3.5) lib/rack/etag.rb:23:in `call'
rack (1.3.5) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/flash.rb:247:in `call'
rack (1.3.5) lib/rack/session/abstract/id.rb:195:in `context'
rack (1.3.5) lib/rack/session/abstract/id.rb:190:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/cookies.rb:331:in `call'
activerecord (3.1.2) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.1.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (3.1.2) lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
activesupport (3.1.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.2) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/reloader.rb:68:in `call'
rack (1.3.5) lib/rack/sendfile.rb:101:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.1.2) lib/rails/rack/logger.rb:13:in `call'
rack (1.3.5) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.1.2) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.5) lib/rack/lock.rb:15:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.1.2) lib/rails/engine.rb:456:in `call'
rack (1.3.5) lib/rack/content_length.rb:14:in `call'
railties (3.1.2) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.3.5) lib/rack/handler/webrick.rb:59:in `service'
/Users/victorstan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/victorstan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/victorstan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Update
If I try to inspect the #admin_message var in the controller #new action the error message changes to indicate and error in the controller instead of the view...
ArgumentError in AdminMessagesController#new
wrong number of arguments (1 for 0)
This happens if I add puts #admin_message.inspect to the controller action new
Moral of the story: Don't use send as a table column name!

ArgumentError in ImagesController#index but appliaction trace is empty

I am calling the index action for a class which gives the following error:
Started GET "/images" for 127.0.0.1 at Sun Aug 28 06:14:41 +0200 2011
Processing by ImagesController#index as HTML Completed 500 Internal
Server Error in 1ms
ArgumentError (wrong number of arguments (2 for 0)):
There is nothing in the application trace, meaning that the failure occurs before any of the files that I created for app get processed. The full trace is here:
activesupport (3.0.8) lib/active_support/callbacks.rb:97:in `send'
activesupport (3.0.8) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (3.0.8) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.8) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
activesupport (3.0.8) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.8) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.8) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.8) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.8) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.8) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.8) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.8) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.8) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.8) lib/action_controller/metal.rb:178:in `action'
actionpack (3.0.8) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.8) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.8) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:82:in `optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.8) lib/action_dispatch/routing/route_set.rb:493:in `call'
sass (3.1.7) lib/sass/./sass/plugin/rack.rb:54:in `call'
warden (1.0.5) lib/warden/manager.rb:35:in `call'
warden (1.0.5) lib/warden/manager.rb:34:in `catch'
warden (1.0.5) lib/warden/manager.rb:34:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.3) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.8) lib/active_record/query_cache.rb:32:in `call'
activerecord (3.0.8) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.8) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.8) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/callbacks.rb:46:in `call'
activesupport (3.0.8) lib/active_support/callbacks.rb:419:in `_run_call_callbacks'
actionpack (3.0.8) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.3) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.8) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.3) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.3) lib/rack/lock.rb:11:in `call'
rack (1.2.3) lib/rack/lock.rb:11:in `synchronize'
rack (1.2.3) lib/rack/lock.rb:11:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.8) lib/rails/application.rb:168:in `call'
railties (3.0.8) lib/rails/application.rb:77:in `send'
railties (3.0.8) lib/rails/application.rb:77:in `method_missing'
railties (3.0.8) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.3) lib/rack/content_length.rb:13:in `call'
rack (1.2.3) lib/rack/handler/webrick.rb:52:in `service'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:162:in `start'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:95:in `start'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:92:in `each'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:92:in `start'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:23:in `start'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:82:in `start'
rack (1.2.3) lib/rack/handler/webrick.rb:13:in `run'
rack (1.2.3) lib/rack/server.rb:217:in `start'
railties (3.0.8) lib/rails/commands/server.rb:65:in `start'
railties (3.0.8) lib/rails/commands.rb:30
railties (3.0.8) lib/rails/commands.rb:27:in `tap'
railties (3.0.8) lib/rails/commands.rb:27
script/rails:6:in `require'
script/rails:6
Here is the relevant code from lib/active_support/callbacks.rb, which I modified to print out the method arguments
def run_callbacks(kind, *args, &block)
p *args
p &block
p kind
send("_run_#{kind}_callbacks", *args, &block)
end
Here is the output with the above code:
"callback arguments"
:checkout
"callback arguments"
"index"
:process_action
Started GET "/images" for 127.0.0.1 at Sun Aug 28 06:40:37 +0200 2011
Processing by ImagesController#index as HTML Completed 500 Internal
Server Error in 1ms
ArgumentError (wrong number of arguments (2 for 0)):
Rendered
/home/jon/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb
(1.5ms) Rendered
/home/jon/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
(8.6ms) Rendered
/home/jon/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb
within rescues/layout (20.9ms)
Here is the DB schema:
create_table "images", :force => true do |t|
t.string "photo"
t.integer "w"
t.integer "h"
t.integer "eyes"
t.integer "head_top"
t.integer "head_bottom"
t.integer "user_id"
t.string "face_params", :limit => 2000
t.string "smiling"
t.string "facing"
t.string "filename"
t.string "content_type"
t.binary "data", :limit => 16777215
t.datetime "created_at"
t.datetime "updated_at"
end
Here is the relevant controller code:
def index
p "made it to index action--------------------------"
if user_signed_in?
#user = current_user
#selected_image = #user.get_selected_image
#problems = #selected_image ? #selected_image.problems.all : Array.new
#images = #user.images - Array[#selected_image]
#image = #user.image_build
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => #images }
end
else
redirect_to root_path
end
end
All the other controllers seem to work. Other actions for this controller give the same error.
Any ideas?
EDIT: Added Routes.rb as per comment below
Id::Application.routes.draw do
resources :payment_notifications
resources :addresses
resources :orders do
member do
get "select_address_for"
put "set_address_for"
get "complete"
end
end
resources :prints do
member do
post "email"
get "confirm_email"
end
end
resources :images do
member do
put "select"
get "thumb"
get "send"
end
end
resources :docs do
member do
get "image_for"
end
end
devise_for :users
##This will redirect the user after sign-in or sign-up.
##Otherwise is will default to the 'root' route, defined below
#devise_for :users do
# get 'users', :to => 'docs#index', :as => :user_root # Rails 3
#end
resources :admins
resources :assistants
resources :books
resources :links
resources :categories
resources :tips
resources :rules
resources :countries
resources :types
resources :continents
# match ':controller(/:action(/:id(.:format)))'
# match ':controller/:action/:id'
# match ':controller/:action/:id.:format'
# match ':controller/:action.:format'
end
You're redefining the send method in your images controller, which is a base ruby method. Rename it to something else and your problem should disappear.