uninitialized constant using associative forms on rails - ruby-on-rails

This has taken my whole day...
I am getting the following error:
uninitialized constant User::Rssfeed
Extracted source (around line #7):
4: <p>You have no feeds chosen</p>
5: <p>Select Feeds</p>
6: <%= #user.id %>
7: <%= form_for ([#user, #user.rssfeeds.build]) do |f| %>
8:
9: <%= f.label :URL %>
10: <%= f.text_field :url %>
These are my files:
routes.rb
PracticeApp::Application.routes.draw do
devise_for :users do
resources :rssfeeds
end
...
user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
has_many :rssfeeds
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
end
rss_feed.rb
class RssFeed < ActiveRecord::Base
belongs_to :user
attr_accessible :title, :url, :user_id
end
I am posting my full Trace after the below comment
I hope this is only the stack trace:
activerecord (3.2.22) lib/active_record/inheritance.rb:111:in `compute_type'
activerecord (3.2.22) lib/active_record/reflection.rb:172:in `klass'
activerecord (3.2.22) lib/active_record/reflection.rb:183:in `build_association'
activerecord (3.2.22) lib/active_record/associations/association.rb:239:in `build_record'
activerecord (3.2.22) lib/active_record/associations/collection_association.rb:112:in `build'
activerecord (3.2.22) lib/active_record/associations/collection_proxy.rb:46:in `build'
app/views/welcome/index.html.erb:7:in `_app_views_welcome_index_html_erb___1736128239453068416_26436840'
actionpack (3.2.22) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.22) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.22) lib/action_view/template.rb:143:in `render'
actionpack (3.2.22) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
actionpack (3.2.22) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.22) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.22) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.22) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.22) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.22) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
actionpack (3.2.22) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
actionpack (3.2.22) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
actionpack (3.2.22) lib/action_view/renderer/template_renderer.rb:18:in `render'
actionpack (3.2.22) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.22) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.22) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.22) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.22) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.22) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.22) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.22) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.22) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.22) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.22) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/home/tech/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
activesupport (3.2.22) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.22) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.22) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.22) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.22) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.2.22) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.2.22) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (3.2.22) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.22) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.22) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.22) lib/active_support/callbacks.rb:425:in `_run__1047168603443753015__process_action__1686181725135518163__callbacks'
activesupport (3.2.22) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.22) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.22) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.22) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.22) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.22) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.22) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.22) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.22) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.22) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.22) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.22) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.22) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.22) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.22) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.22) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.22) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.22) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.22) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.22) 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.22) lib/action_dispatch/routing/route_set.rb:608:in `call'
warden (1.2.4) lib/warden/manager.rb:35:in `block in call'
warden (1.2.4) lib/warden/manager.rb:34:in `catch'
warden (1.2.4) lib/warden/manager.rb:34:in `call'
actionpack (3.2.22) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.7) lib/rack/etag.rb:23:in `call'
rack (1.4.7) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.22) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.22) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.22) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.7) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.7) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.22) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.22) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.22) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.22) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.22) lib/active_support/callbacks.rb:405:in `_run__4304564743745214979__call__3915293872623649341__callbacks'
activesupport (3.2.22) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.22) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.22) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.22) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.22) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.22) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.22) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.22) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.22) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.22) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.22) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.22) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.22) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.7) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.7) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.22) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.7) lib/rack/lock.rb:15:in `call'
actionpack (3.2.22) lib/action_dispatch/middleware/static.rb:83:in `call'
railties (3.2.22) lib/rails/engine.rb:484:in `call'
railties (3.2.22) lib/rails/application.rb:231:in `call'
rack (1.4.7) lib/rack/content_length.rb:14:in `call'
railties (3.2.22) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.7) lib/rack/handler/webrick.rb:59:in `service'
/home/tech/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/home/tech/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/home/tech/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'

because you've said that a user has many :rssfeeds, it is expecting a class called Rssfeed and you have one called RssFeed.
Two options:
Change the class to Rssfeed:
class RssFeed < ActiveRecord::Base
belongs_to :user
attr_accessible :title, :url, :user_id
end
Or change the association:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
has_many :rss_feeds
end
<p>You have no feeds chosen</p>
5: <p>Select Feeds</p>
6: <%= #user.id %>
7: <%= form_for ([#user, #user.rss_feeds.build]) do |f| %>
8:
9: <%= f.label :URL %>
10: <%= f.text_field :url %>

Related

Nested attributes with ruby on rails

I'm developing a system to improve my Rails skills, which will allow anyone to create a user. This user will have an inventory, which will contain multiple items.
My question is how can I store all the resources when saving a new user. I'm trying to use cocoon gem, and I got this error message:
undefined method `new_record?' for nil:NilClass
at this part of the code:
<%= link_to_remove_association "remove item", f %>
Models
class User < ActiveRecord::Base
has_one :inventory
delegate :items, to: :inventory, prefix: true
accepts_nested_attributes_for :inventory
end
class Inventory < ActiveRecord::Base
has_many :inventory_items
has_many :items, through: :inventory_items
accepts_nested_attributes_for :inventory_items, reject_if: :all_blank, allow_destroy: true
end
class InventoryItem < ActiveRecord::Base
belongs_to :item
belongs_to :inventory
end
Controller
class UsersController < ApplicationController
def new
#user = User.new.tap do |user|
user.inventory = Inventory.new
user.inventory_items.build
end
end
private
def user_params
params
.require(:user)
.permit(
:name,
:lat,
:long,
:age,
inventory_attributes: [:id, inventory_items_attributes: [:quantity, :inventory_id, :item_id, :_destroy]]
)
end
end
User form
<%= simple_form_for(#user) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :name %>
<%= f.input :lat %>
<%= f.input :long %>
</div>
<h3>Items</h3>
<div id="inventory_items">
<%= f.simple_fields_for :inventory do |inventory| %>
<%= inventory.simple_fields_for :inventory_items do |f| %>
<%= render 'item_fields', f: f %>
<% end %>
<% end %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
item_fields partial
<div class="nested-fields">
<%= f.collection_select :item_id, Item.all, :id, :name %>
<%= f.input :quantity %>
<%= link_to_remove_association "remove item", f %>
</div>
The inventory does not have more attributes than its id and user_id
Stack trace
cocoon (1.2.9) lib/cocoon/view_helpers.rb:29:in `link_to_remove_association'
app/views/users/_inventory_item_fields.html.erb:6:in `_app_views_users__inventory_item_fields_html_erb__1201857070210368281_70056778972140'
actionview (4.2.4) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.4) lib/active_support/notifications.rb:166:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:333:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:143:in `render'
actionview (4.2.4) lib/action_view/renderer/partial_renderer.rb:339:in `render_partial'
actionview (4.2.4) lib/action_view/renderer/partial_renderer.rb:310:in `block in render'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
actionview (4.2.4) lib/action_view/renderer/partial_renderer.rb:309:in `render'
actionview (4.2.4) lib/action_view/renderer/renderer.rb:47:in `render_partial'
actionview (4.2.4) lib/action_view/helpers/rendering_helper.rb:35:in `render'
app/views/users/new.html.erb:12:in `block (3 levels) in _app_views_users_new_html_erb___3186868675472137201_70056772986280'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:202:in `with_output_buffer'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `capture'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:714:in `fields_for'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:1599:in `fields_for'
simple_form (3.1.1) lib/simple_form/action_view_extensions/builder.rb:27:in `simple_fields_for'
app/views/users/new.html.erb:11:in `block (2 levels) in _app_views_users_new_html_erb___3186868675472137201_70056772986280'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:202:in `with_output_buffer'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `capture'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:1925:in `block in fields_for_nested_model'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:202:in `with_output_buffer'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `capture'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:714:in `fields_for'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:1924:in `fields_for_nested_model'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:1914:in `fields_for_with_nested_attributes'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:1582:in `fields_for'
simple_form (3.1.1) lib/simple_form/action_view_extensions/builder.rb:27:in `simple_fields_for'
app/views/users/new.html.erb:10:in `block in _app_views_users_new_html_erb___3186868675472137201_70056772986280'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:202:in `with_output_buffer'
actionview (4.2.4) lib/action_view/helpers/capture_helper.rb:38:in `capture'
actionview (4.2.4) lib/action_view/helpers/form_helper.rb:444:in `form_for'
simple_form (3.1.1) lib/simple_form/action_view_extensions/form_helper.rb:26:in `block in simple_form_for'
simple_form (3.1.1) lib/simple_form/action_view_extensions/form_helper.rb:45:in `with_simple_form_field_error_proc'
simple_form (3.1.1) lib/simple_form/action_view_extensions/form_helper.rb:25:in `simple_form_for'
app/views/users/new.html.erb:1:in `_app_views_users_new_html_erb___3186868675472137201_70056772986280'
actionview (4.2.4) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.4) lib/active_support/notifications.rb:166:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:333:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:143:in `render'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:14:in `render'
actionview (4.2.4) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (4.2.4) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (4.2.4) lib/action_view/rendering.rb:100:in `_render_template'
actionpack (4.2.4) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (4.2.4) lib/action_view/rendering.rb:83:in `render_to_body'
actionpack (4.2.4) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
actionpack (4.2.4) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
actionpack (4.2.4) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (4.2.4) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
activesupport (4.2.4) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/home/vinicius/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
activesupport (4.2.4) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
activerecord (4.2.4) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:43:in `render'
actionpack (4.2.4) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.2.4) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (4.2.4) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.4) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.4) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.4) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.4) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.4) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
activesupport (4.2.4) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.4) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.4) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
activesupport (4.2.4) lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
activesupport (4.2.4) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.4) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.4) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.4) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.4) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.4) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.4) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.4) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.4) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.4) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:76:in `call'
actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:45:in `serve'
actionpack (4.2.4) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.4) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.4) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:821:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.4) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
activerecord (4.2.4) lib/active_record/migration.rb:377:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.4) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.4) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.4) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.4) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.4) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.4) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/static.rb:116:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.4) lib/rails/engine.rb:518:in `call'
railties (4.2.4) lib/rails/application.rb:165:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'

Rails/Pundit ArgumentError

In an exercise, I'm trying to create authorization such that a user needs to be either the post's owner or the general administrator, on top of being present and logged-in to update a post. I am trying to implement a pundit policy (using Devise for authentication).
The PostController Class:
class PostsController < ApplicationController
...
def edit
#post = Post.find(params[:id])
authorize #post
end
...
end
The ApplicationPolicy Class:
class ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
#user = user
#record = record
end
...
def update?
user.present? && (record.user == user || user.role?(:admin))
end
def edit?
update?
end
def destroy?
update?
end
...
end
* The User model* :
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
has_many :posts
def role?(base_role)
role == base_role.to_s
end
end
I got stuck with the Argument Error: wrong number of arguments (2 for 1). My understanding is that the policy method is part of the Pundit module, and it initializes and returns a new policy object with the given record and current_user as the implicit user. Can someone help me shed a light into this issue?
ERROR MESSAGE:
Showing /home/vagrant/code/bloccit/app/views/posts/show.html.erb where line #3 raised:
<h1><%= #post.title %></h1>
<% if policy(#post).edit? %> #This is the line where the error is raised.
<%= link_to "Edit", edit_post_path(#post), class: 'btn btn-success' %>
<% end %>
wrong number of arguments (2 for 1)
Full error trace :
activerecord (4.0.10) lib/active_record/attribute_methods/query.rb:35:in `attribute?'
activemodel (4.0.10) lib/active_model/attribute_methods.rb:383:in `role?'
app/policies/application_policy.rb:26:in `update?'
app/policies/application_policy.rb:30:in `edit?'
app/views/posts/show.html.erb:3:in `_app_views_posts_show_html_erb__322214668_90107450'
actionpack (4.0.10) lib/action_view/template.rb:143:in `block in render'
activesupport (4.0.10) lib/active_support/notifications.rb:161:in `instrument'
actionpack (4.0.10) lib/action_view/template.rb:141:in `render'
actionpack (4.0.10) lib/action_view/renderer/template_renderer.rb:49:in `block (2 levels) in render_template'
actionpack (4.0.10) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (4.0.10) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.10) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.10) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.10) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (4.0.10) lib/action_view/renderer/template_renderer.rb:48:in `block in render_template'
actionpack (4.0.10) lib/action_view/renderer/template_renderer.rb:56:in `render_with_layout'
actionpack (4.0.10) lib/action_view/renderer/template_renderer.rb:47:in `render_template'
actionpack (4.0.10) lib/action_view/renderer/template_renderer.rb:17:in `render'
actionpack (4.0.10) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionpack (4.0.10) lib/action_view/renderer/renderer.rb:23:in `render'
actionpack (4.0.10) lib/abstract_controller/rendering.rb:127:in `_render_template'
actionpack (4.0.10) lib/action_controller/metal/streaming.rb:219:in `_render_template'
actionpack (4.0.10) lib/abstract_controller/rendering.rb:120:in `render_to_body'
actionpack (4.0.10) lib/action_controller/metal/rendering.rb:33:in `render_to_body'
actionpack (4.0.10) lib/action_controller/metal/renderers.rb:26:in `render_to_body'
actionpack (4.0.10) lib/abstract_controller/rendering.rb:97:in `render'
actionpack (4.0.10) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.0.10) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
activesupport (4.0.10) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/home/vagrant/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
activesupport (4.0.10) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.0.10) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
actionpack (4.0.10) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.0.10) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.0.10) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (4.0.10) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.0.10) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (4.0.10) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.10) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.10) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.10) lib/active_support/callbacks.rb:413:in `_run__423379461__process_action__callbacks'
activesupport (4.0.10) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.10) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.10) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.10) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.10) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.10) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.10) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.10) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.10) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.0.10) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.10) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.10) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.10) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.10) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.10) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.10) lib/action_dispatch/routing/route_set.rb:82:in `call'
actionpack (4.0.10) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
actionpack (4.0.10) lib/action_dispatch/routing/route_set.rb:50:in `call'
actionpack (4.0.10) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.10) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.10) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.10) lib/action_dispatch/routing/route_set.rb:676: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:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/flash.rb:241: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.0.10) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.10) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.10) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.10) lib/active_record/migration.rb:373:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.10) lib/active_support/callbacks.rb:373:in `_run__474745028__call__callbacks'
activesupport (4.0.10) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.10) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.10) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.10) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.10) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.0.10) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.0.10) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.0.10) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.10) 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.0.10) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.10) lib/rails/engine.rb:511:in `call'
railties (4.0.10) lib/rails/application.rb:97: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'
/home/vagrant/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/vagrant/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/vagrant/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
The first 2-3 lines of the error trace tell us the problem is in ApplicationPolicy#update? and User#role?:
activerecord (4.0.10) lib/active_record/attribute_methods/query.rb:35:in attribute?'
activemodel (4.0.10) lib/active_model/attribute_methods.rb:383:in role?'
app/policies/application_policy.rb:26:in update?'
Looking at the code in question:
class ApplicationPolicy
...
def update?
user.present? && (record.user == user || user.role?(:admin))
end
...
end
Here's a few things to try:
Check User has a role? method defined on it.
Check User#role? is being found and called. Insert logging or a raise "In User#role?" statement into the method to be certain.
Ensure db migrations have run on development and test environments by running the rake db:migrate and rake db:migrate RAILS_ENV=test tasks.
Restart the server rails s

Why does Simple_Form's association method throw the "wrong number of arguments (0 for 1)" exception?

The association method from simple_form is throwing an exception on the most basic use, and I cannot figure out why. I'd appreciate any help.
I have a has_and_belongs_to_many association between the Users and Projects models:
project.rb:
class Project < ActiveRecord::Base
has_and_belongs_to_many :users
belongs_to :owner, :class_name => "User", :foreign_key => "owner_id"
...
user.rb:
class User < ActiveRecord::Base
has_and_belongs_to_many :projects
has_many :projects_owned, :class_name => "Project", :foreign_key => "owner_id"
...
edit.html.erb:
<%= simple_form_for #project do |f| %>
<%= f.input :name, input_html: { size: 61 } %>
<%= f.input :description, as: :text, input_html: { cols: 60 } %>
<%= f.association(:users) %>
<%= f.submit "Save project", class: "btn btn-large btn-primary" %>
<% end %>
All models have corresponding tables, and the association works correclty in Rspec tests and the Rails console.
When I build the form, exactly as specified in the simple_form documentation, I get the following error:
<ArgumentError: wrong number of arguments (0 for 1)>
Stack trace:
ArgumentError - wrong number of arguments (0 for 1):
simple_form (3.0.1) lib/simple_form/inputs/collection_input.rb:87:in `collection_includes_basic_objects?'
simple_form (3.0.1) lib/simple_form/inputs/collection_input.rb:70:in `detect_common_display_methods'
simple_form (3.0.1) lib/simple_form/inputs/collection_input.rb:57:in `detect_collection_methods'
simple_form (3.0.1) lib/simple_form/inputs/collection_select_input.rb:5:in `input'
simple_form (3.0.1) lib/simple_form/wrappers/many.rb:29:in `block in render'
simple_form (3.0.1) lib/simple_form/wrappers/many.rb:27:in `render'
simple_form (3.0.1) lib/simple_form/wrappers/root.rb:15:in `render'
simple_form (3.0.1) lib/simple_form/form_builder.rb:120:in `input'
simple_form (3.0.1) lib/simple_form/form_builder.rb:212:in `association'
app/views/projects/edit.html.erb:12:in `block in _app_views_projects_edit_html_erb___630637963_32694600'
actionpack (4.0.4) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
actionpack (4.0.4) lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
actionpack (4.0.4) lib/action_view/helpers/capture_helper.rb:38:in `capture'
actionpack (4.0.4) lib/action_view/helpers/form_helper.rb:435:in `form_for'
simple_form (3.0.1) lib/simple_form/action_view_extensions/form_helper.rb:22:in `block in simple_form_for'
simple_form (3.0.1) lib/simple_form/action_view_extensions/form_helper.rb:41:in `with_simple_form_field_error_proc'
simple_form (3.0.1) lib/simple_form/action_view_extensions/form_helper.rb:21:in `simple_form_for'
app/views/projects/edit.html.erb:9:in `_app_views_projects_edit_html_erb___630637963_32694600'
actionpack (4.0.4) lib/action_view/template.rb:143:in `block in render'
activesupport (4.0.4) lib/active_support/notifications.rb:161:in `instrument'
actionpack (4.0.4) lib/action_view/template.rb:141:in `render'
actionpack (4.0.4) lib/action_view/renderer/template_renderer.rb:49:in `block (2 levels) in render_template'
actionpack (4.0.4) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (4.0.4) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.4) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.4) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (4.0.4) lib/action_view/renderer/template_renderer.rb:48:in `block in render_template'
actionpack (4.0.4) lib/action_view/renderer/template_renderer.rb:56:in `render_with_layout'
actionpack (4.0.4) lib/action_view/renderer/template_renderer.rb:47:in `render_template'
actionpack (4.0.4) lib/action_view/renderer/template_renderer.rb:17:in `render'
actionpack (4.0.4) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionpack (4.0.4) lib/action_view/renderer/renderer.rb:23:in `render'
actionpack (4.0.4) lib/abstract_controller/rendering.rb:127:in `_render_template'
actionpack (4.0.4) lib/action_controller/metal/streaming.rb:219:in `_render_template'
actionpack (4.0.4) lib/abstract_controller/rendering.rb:120:in `render_to_body'
actionpack (4.0.4) lib/action_controller/metal/rendering.rb:33:in `render_to_body'
actionpack (4.0.4) lib/action_controller/metal/renderers.rb:26:in `render_to_body'
actionpack (4.0.4) lib/abstract_controller/rendering.rb:97:in `render'
actionpack (4.0.4) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.0.4) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
activesupport (4.0.4) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
activesupport (4.0.4) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.0.4) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
actionpack (4.0.4) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.0.4) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.0.4) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (4.0.4) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.0.4) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (4.0.4) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.4) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.4) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.4) lib/active_support/callbacks.rb:413:in `_run__482912548__process_action__callbacks'
activesupport (4.0.4) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.4) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.4) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.4) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.4) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.4) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.4) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.0.4) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.4) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.4) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.4) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.4) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.4) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.4) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.4) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.4) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.4) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.4) lib/action_dispatch/routing/route_set.rb:674:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/flash.rb:241: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.0.4) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.4) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.4) lib/active_record/migration.rb:373:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.4) lib/active_support/callbacks.rb:373:in `_run__957210712__call__callbacks'
activesupport (4.0.4) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
better_errors (1.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:56:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.4) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.0.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.0.4) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.0.4) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.4) 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.0.4) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.4) lib/rails/engine.rb:511:in `call'
railties (4.0.4) lib/rails/application.rb:97: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'
The problem has something to do with the collection for the form field.
See if this works:
<%= f.association :users, collection: User.all %>
I haven't tracked down why the collection is needed yet, but that seems to be the problem.

Non working render

I get the errors message in the title and I can't understand why?
this my code
user.rb
has_one :GoldBook
has_many :comments
gold_book.rb
has_many :comments
belongs_to :user
comment.rb
belongs_to :user
belongs_to :gold_book
comments_controller.rb
def create
#gold_book = GoldBook.find(params[:gold_book_id])
#comment = Comment.new(params[:comment])
#comment.goldbook = #gold_book
#comment.user = current_user
gold_books/show.html.erb
<%= render 'goldbook' %>
gold_books/_goldbooks
<%= render 'comments/form', goldbook: goldbook %>
comments/_form
<%= form_for([goldbook, #comment]) do |f| %>
<% if #comment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
<ul>
<% #comment.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :content %><br />
<%= f.text_area :content %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
I think the error is in the comments' form but not sure ...
I'm trying to make somethink like a gold book with many comment
And this is the full trace error :
activemodel (3.2.8) lib/active_model/naming.rb:163:in `model_name_from_record_or_class'
activemodel (3.2.8) lib/active_model/naming.rb:158:in `param_key'
actionpack (3.2.8) lib/action_view/helpers/form_helper.rb:369:in `form_for'
app/views/comments/_form.html.erb:1:in `_app_views_comments__form_html_erb__1022796803_80617610'
actionpack (3.2.8) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.8) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.8) lib/action_view/template.rb:143:in `render'
actionpack (3.2.8) lib/action_view/renderer/partial_renderer.rb:265:in `render_partial'
actionpack (3.2.8) lib/action_view/renderer/partial_renderer.rb:238:in `block in render'
actionpack (3.2.8) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
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_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.8) lib/action_view/renderer/partial_renderer.rb:237:in `render'
actionpack (3.2.8) lib/action_view/renderer/renderer.rb:41:in `render_partial'
actionpack (3.2.8) lib/action_view/helpers/rendering_helper.rb:27:in `render'
app/views/gold_books/_goldbook.html.erb:3:in `_app_views_gold_books__goldbook_html_erb__357761412_79186410'
actionpack (3.2.8) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.8) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.8) lib/action_view/template.rb:143:in `render'
actionpack (3.2.8) lib/action_view/renderer/partial_renderer.rb:265:in `render_partial'
actionpack (3.2.8) lib/action_view/renderer/partial_renderer.rb:238:in `block in render'
actionpack (3.2.8) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
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_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.8) lib/action_view/renderer/partial_renderer.rb:237:in `render'
actionpack (3.2.8) lib/action_view/renderer/renderer.rb:41:in `render_partial'
actionpack (3.2.8) lib/action_view/helpers/rendering_helper.rb:27:in `render'
app/views/gold_books/show.html.erb:7:in `_app_views_gold_books_show_html_erb__197041322_85056980'
actionpack (3.2.8) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.8) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.8) lib/action_view/template.rb:143:in `render'
actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
actionpack (3.2.8) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
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_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:18:in `render'
actionpack (3.2.8) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.8) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.8) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.8) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.8) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.8) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.8) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.8) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.8) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.8) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/usr/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
activesupport (3.2.8) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.8) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.2.8) lib/action_controller/metal/mime_responds.rb:196:in `respond_to'
app/controllers/gold_books_controller.rb:18:in `show'
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:414:in `_run__799128830__process_action__547441087__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'
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'
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__1022103052__call__645886376__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'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Associations are case-sensitive. Change this:
has_one :GoldBook
to
has_one :gold_book
Also, your instance variable is called #gold_book, but in your show view you're referring to goldbook. Try changing it to:
<%= render 'comments/form', gold_book: #gold_book %>
In general, make sure you adhere to the naming conventions of Rails. Take a look at this guide, particularly the section on "Rendering by default".

form_for undefined method `model_name' error

I'm having problem with form_for, have searched for the problem for the solutions given does not solve my problem.
I'm trying to do up a form to create new recipes:
**app/views/recipes/new.html.erb**
<%= form_for #recipe do |f| %>
<% if #recipe.errors.any? %>
<% end %>
<div class="field">
<%= f.label :recipename %><br />
<%= f.text_area :recipename %>
</div>
<div class="field">
<%= f.label :user_id %><br />
<%= f.number_field :user_id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
**routes.rb**
Baserecipe::Application.routes.draw do
resources :users
resources :recipes
....
match '/createrecipe', to: 'recipes#new'
**recipes_controller.rb**
class RecipesController < ApplicationController
def create
#recipe = Recipe.new(params[:recipe])
end
end
I'm alway getting the error:
undefined method `model_name' for NilClass:Class
Extracted source (around line #1):
1: <%= form_for #recipe do |f| %>
2: <% if #recipe.errors.any? %>
3: <% end %>
class Recipe < ActiveRecord::Base
attr_accessible :recipename, :instruct1, :instruct2, :instruct3, :instruct4, :instruct5,
:instruct6, :instruct7, :instruct8, :instruct9, :instruct10, :instruct11, :instruct12,
:instruct13, :instruct14, :instruct15, :instruct16, :instruct17, :instruct18, :instruct19,
:instruct20, :instruct21, :instruct22, :instruct23, :instruct24, :instruct25, :instruct26,
:instruct27, :instruct28, :instruct29, :instruct30, :preptime, :cooktime
belongs_to :user
has_many :ingredients
has_many :rcomments
validates :recipename, presence: true, length: { maximum: 140 }
validates :user_id, presence: true
validates :preptime, presence: true
validates :cooktime, presence: true
default_scope order: 'recipes.created_at DESC'
end
full trace:
activemodel (3.2.7) lib/active_model/naming.rb:163:in `model_name_from_record_or_class'
activemodel (3.2.7) lib/active_model/naming.rb:158:in `param_key'
actionpack (3.2.7) lib/action_view/helpers/form_helper.rb:369:in `form_for'
app/views/recipes/new.html.erb:3:in `_app_views_recipes_new_html_erb___168565054_39061080'
actionpack (3.2.7) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.7) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.7) lib/action_view/template.rb:143:in `render'
actionpack (3.2.7) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
actionpack (3.2.7) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.7) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.7) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.7) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.7) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.7) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
actionpack (3.2.7) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
actionpack (3.2.7) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
actionpack (3.2.7) lib/action_view/renderer/template_renderer.rb:18:in `render'
actionpack (3.2.7) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.7) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.7) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.7) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.7) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.7) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.7) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.7) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.7) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.7) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.7) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
c:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
activesupport (3.2.7) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.7) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.7) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.7) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.7) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.2.7) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.2.7) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (3.2.7) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.7) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.7) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.7) lib/active_support/callbacks.rb:414:in `_run__22188539__process_action__1016913818__callbacks'
activesupport (3.2.7) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.7) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.7) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.7) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.7) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.7) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.7) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.7) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.7) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.7) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.7) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.7) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.7) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.7) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.7) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.7) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.7) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.7) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.7) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.7) 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.7) lib/action_dispatch/routing/route_set.rb:600:in `call'
actionpack (3.2.7) 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.7) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.7) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.7) 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.7) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.7) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `call'
actionpack (3.2.7) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.7) lib/active_support/callbacks.rb:405:in `_run__305680696__call__774818341__callbacks'
activesupport (3.2.7) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.7) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.7) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.7) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.7) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.7) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.7) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.7) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.7) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.7) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.7) 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.7) 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.7) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.7) lib/rails/engine.rb:479:in `call'
railties (3.2.7) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.7) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
c:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
c:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
c:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
try this
# in your recipes_controller.rb
def new
#recipe = Recipe.new
end
and remove
match '/createrecipe', to: 'recipes#new'
#in routes.rb
Baserecipe::Application.routes.draw do
resources :users
resources :recipes
....
see more info about route
your model file look like - recipe.rb
class Recipe < ActiveRecord::Base
...
...
end

Resources