I started getting this error:
NoMethodError: undefined method `has_key?' for nil:NilClass
in the process of nearly finishing Hartl's excellent Rails Tutorial. It looks like I must have left out a method, but I have idea where, and am new to debugging in Rails.
Here's the full stack trace:
activerecord (3.0.9) lib/active_record/attribute_methods/read.rb:80:in `id'
activerecord (3.0.9) lib/active_record/attribute_methods/primary_key.rb:9:in `to_key'
actionpack (3.0.9) lib/action_controller/record_identifier.rb:82:in `record_key_for_dom_id'
actionpack (3.0.9) lib/action_controller/record_identifier.rb:63:in `dom_id'
actionpack (3.0.9) lib/action_view/helpers/form_helper.rb:331:in `apply_form_for_options!'
actionpack (3.0.9) lib/action_view/helpers/form_helper.rb:313:in `form_for'
app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___834068491__620833808_0'
actionpack (3.0.9) lib/action_view/template.rb:135:in `send'
actionpack (3.0.9) lib/action_view/template.rb:135:in `render'
activesupport (3.0.9) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.9) lib/action_view/template.rb:127:in `render'
actionpack (3.0.9) lib/action_view/render/rendering.rb:59:in `_render_template'
activesupport (3.0.9) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.9) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.9) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.9) lib/action_view/render/rendering.rb:56:in `_render_template'
actionpack (3.0.9) lib/action_view/render/rendering.rb:26:in `render'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:115:in `_render_template'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:109:in `render_to_body'
actionpack (3.0.9) lib/action_controller/metal/renderers.rb:47:in `render_to_body'
actionpack (3.0.9) lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:102:in `render_to_string'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:93:in `render'
actionpack (3.0.9) lib/action_controller/metal/rendering.rb:17:in `render'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:40:in `render'
activesupport (3.0.9) lib/active_support/core_ext/benchmark.rb:5:in `ms'
/usr/lib/ruby/1.8/benchmark.rb:308:in `realtime'
activesupport (3.0.9) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.0.9) lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.0.9) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.0.9) lib/action_controller/metal/mime_responds.rb:261:in `retrieve_response_from_mimes'
actionpack (3.0.9) lib/action_controller/metal/mime_responds.rb:192:in `call'
actionpack (3.0.9) lib/action_controller/metal/mime_responds.rb:192:in `respond_to'
app/controllers/users_controller.rb:29:in `new'
actionpack (3.0.9) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.9) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.9) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.9) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.9) lib/abstract_controller/callbacks.rb:18:in `process_action'
activesupport (3.0.9) lib/active_support/callbacks.rb:436:in `_run__434435962__process_action__943997142__callbacks'
activesupport (3.0.9) lib/active_support/callbacks.rb:410:in `send'
activesupport (3.0.9) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.9) lib/active_support/callbacks.rb:94:in `send'
activesupport (3.0.9) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.9) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
activesupport (3.0.9) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.9) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.9) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.9) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.9) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.9) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.9) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.9) lib/action_controller/metal.rb:178:in `action'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.9) 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:103: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.9) lib/action_dispatch/routing/route_set.rb:493:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.3) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.9) lib/active_record/query_cache.rb:32:in `call'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.9) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.9) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:46:in `call'
activesupport (3.0.9) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.3) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.9) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.3) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.9) 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.9) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.9) lib/rails/application.rb:168:in `call'
railties (3.0.9) lib/rails/application.rb:77:in `send'
railties (3.0.9) lib/rails/application.rb:77:in `method_missing'
railties (3.0.9) 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'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/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.9) lib/rails/commands/server.rb:65:in `start'
railties (3.0.9) lib/rails/commands.rb:30
railties (3.0.9) lib/rails/commands.rb:27:in `tap'
railties (3.0.9) lib/rails/commands.rb:27
script/rails:6:in `require'
script/rails:6
I can see that the error is because a User is not getting created during the signin process.
So I went into the console, and just tried to create a User; here's the error stack from that:
from script/rails:6irb(main):004:0> user=User.new
NoMethodError: undefined method `has_key?' for nil:NilClass
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/whiny_nil.rb:48:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active_record/base.rb:1512:in `has_attribute?'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active_record/base.rb:1672:in `inspect'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active_record/base.rb:1671:in `collect'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active_record/base.rb:1671:in `inspect'
from /usr/lib/ruby/1.8/irb.rb:310:in `output_value'
from /usr/lib/ruby/1.8/irb.rb:159:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:271:in `signal_status'
from /usr/lib/ruby/1.8/irb.rb:155:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:154:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:71:in `start'
from /usr/lib/ruby/1.8/irb.rb:70:in `catch'
from /usr/lib/ruby/1.8/irb.rb:70:in `start'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.9/lib/rails/commands/console.rb:44:in `start'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.9/lib/rails/commands/console.rb:8:in `start'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.9/lib/rails/commands.rb:23
from script/rails:6:in `require'
I'm using Rails 3.0.9. If anyone can point me in the right direction, sure would appreciate it!
thanks,
rick
Additional post (9/27/11):
to help my commenters --
yes, I've migrated my database.
where I'm at in the Tutorial: I've basically finished the tutorial, but differed from how it coded up Users, but using a scaffold instead of the incremental approach that Hartl takes.
here's users/new.html.erb:
<h1>New user</h1>
<%= form_for(#user) do |f| %>
<div class="field">
<%= f.label :firstname, "First Name" %><br />
<%= f.text_field :firstname %>
</div>
<div class="field">
<%= f.label :lastname, "Last Name" %><br />
<%= f.text_field :lastname %>
</div>
<div class="field">
<%= f.label :username %><br />
<%= f.text_field :username %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirmation" %><br />
<%= f.password_field :password_confirmation %>
</div>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
<%= link_to 'Back', users_path %>
Where I think is causing my bug is that a user object does not get created by the model, for some reason; and that's why I get the 'nil object' error.
Any help much appreciated!
--rick
Welcome to Rails and to debugging a Rails program.
Some general debugging tips.
While the nil object does have a number of methods, it is obviously not an ActiveRecord object and thus doesn't have the has_key? method.
So the problem (as you surmised) is that the method that should return an ActiveRecord object is returning nil instead.
So next is to figure out why. Since you're trying to create the ActiveRecord object it may well be that the object is not passing its validations. Check this by using valid? before saving. Or use save! instead of save The save! method will throw an error if the save operation doesn't succeed.
Learn how to use the logging statement to send log messages to the log file as you debug.
You can also use the interactive debugger. It can be set up so it'll be invoked when the browser's request reaches a particular line of code in the server. -- The browser will sit with an hour-glass until you "continue" within the debugger.
Added Debugging validations
To debug validations, I use a couple of techniques:
Don't try to use the debugger to follow the execution of the validations--as you've seen, that's a mug's game.
Do use the debugger to invoke the save or valid? method on the AR object. You can then inspect the object or use a method to view the error object that is contained within the AR object. The error object will often tell you which validation failed.
You can also individually comment out validations until you find the one that is giving you a problem.
You can also use the debugger to examine the attributes of the AR object to see whether the attribute values will pass validation or not.
Re: when do validations run (as you ask in your comment). Do remember that by default, validations will run on create as well as update calls. If you want an individual validation to only be checked on update (not on create), there are several ways to do that, check the docs for the individual validation.
There's more to say about validations. If you have a specific validation that fails and you don't understand why it is failing, then open a separate question in SO.
Re: why do validations have to be passed on creation, not just updates -- that's a feature. It enables you to assure yourself that only valid objects are being created in the db. But you don't have to use it. You can set validations to only be active on Update.
Validations are a powerful, sophisticated part of ActiveRecord. In other words, they can be complicated until they're understood.
Maybe on your User model you were creating an initialize method that overrode ActiveRecord:Base
script/console
class User < ActiveRecord:Base
def initialize
end
end
User.new
=> NoMethodError: undefined method `has_key?' for nil:NilClass
Related
I have the following error when submitting my registration information:
NoMethodError in Devise::RegistrationsController#create
undefined method `downcase!' for 0:Fixnum
\livu_pamatskola\app\views\devise\registrations\new.html.erb:
<h1>Reģistrācija</h1>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div id="contacts">
<div id="title"><%= f.label "Vārds" %></div>
<div id="information"><%= f.text_field :name %></div>
<div style="clear: both;"></div>
<div id="title"><%= f.label "Uzvārds" %></div>
<div id="information"><%= f.text_field :surname %></div>
<div style="clear: both;"></div>
<div id="title"><%= f.label "E-pasts" %></div>
<div id="information"><%= f.text_field :email, :autofocus => true %></div>
<div style="clear: both;"></div>
<div id="title"><%= f.label "Parole" %></div>
<div id="information"><%= f.password_field :password %></div>
<div style="clear: both;"></div>
<div id="title"><%= f.label "Vēlreiz parole" %></div>
<div id="information"><%= f.password_field :password_confirmation %></div>
</div>
<div><%= f.submit "Reģistrēties", :id => "button-link" %></div>
<% end %>
I understand that the problem is in Registrations Controller, as I think, but I don't have a such controller. I have searched all over the internet for solutions, but I haven't find anything, just spent a lot of time, so I need your help.
Trace:
activesupport (3.2.8) lib/active_support/core_ext/object/try.rb:36:in `try'
devise (2.2.1) lib/devise/models/authenticatable.rb:172:in `apply_to_attribute_or_variable'
devise (2.2.1) lib/devise/models/authenticatable.rb:163:in `block in downcase_keys'
devise (2.2.1) lib/devise/models/authenticatable.rb:163:in `each'
devise (2.2.1) lib/devise/models/authenticatable.rb:163:in `downcase_keys'
activesupport (3.2.8) lib/active_support/callbacks.rb:407:in `_run__271922054__validation__371060191__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'
devise (2.2.1) app/controllers/devise/registrations_controller.rb:15:in `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__1051681660__process_action__714589613__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'
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.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:35: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.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.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__646451992__call__371060191__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.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) 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.5) 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.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.8) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
c:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
c:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
c:/Ruby193/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Problem solved:
When I was creating my user model for Devise, I included email attribute in migration. Problem was there when adding devise to user model, it adds email fields by default too, so it was conflicting with my previous migration.
I am glad that I have solved it, because I don't have a time for these bugs. Thank you all for helping.
It looks like your user model has wrong type of attributes. Make sure your database contains valid type of fields. Learn more here: https://github.com/plataformatec/devise
Your problem might be related to known case-insensitive keys issue. Add folowing snippet to your config/initializers/devise.rb file: http://anti-pattern.com/case-insensitive-keys-with-devise
Registration controller is defined in Devise library and it is automatically added to your application controllers if you add devise to the Gemfile.
Are you submitting numerical information for some of the fields? Like, "123" for the username? That could be an issue with Devise if it is getting a number as a string, but thinking it's actually a number.
I'm new to rails, and ruby. I'm creating a simple application where I can upload a photo. I have the paperclip gem installed and I'm trying to configure it within my model to specify a thumbnail size like so:
has_attached_file :photo,
:styles => {:thumb => '120x120>', :large => '640x480>' },
:default_style => :thumb,
:url => "/system/photos/:basename.:extension",
:path => ":rails_root/public/system/photos/:basename.:extension"
However, I keep receiving the error:
undefined method `match' for nil:NilClass
When I remove the :styles parameter, everything works as expected.
Can anybody shed some light and point me in the right direction?
Thanks
EDIT:
Stack trace is as follows:
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/content_type_detector.rb:60:in `type_from_file_command'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/content_type_detector.rb:16:in `detect'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/io_adapters/file_adapter.rb:14:in `cache_current_values'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/io_adapters/file_adapter.rb:5:in `initialize'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/io_adapters/registry.rb:29:in `new'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/io_adapters/registry.rb:29:in `for'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/attachment.rb:412:in `post_process_style'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/attachment.rb:402:in `block in post_process_styles'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/attachment.rb:401:in `each'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/attachment.rb:401:in `post_process_styles'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/attachment.rb:394:in `block (2 levels) in post_process'
activesupport (3.2.7) lib/active_support/callbacks.rb:403:in `_run__792123923__photo_post_process__530674861__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_photo_post_process_callbacks'
activesupport (3.2.7) lib/active_support/callbacks.rb:81:in `run_callbacks'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/callbacks.rb:26:in `run_paperclip_callbacks'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/attachment.rb:393:in `block in post_process'
activesupport (3.2.7) lib/active_support/callbacks.rb:403:in `_run__792123923__post_process__530674861__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_post_process_callbacks'
activesupport (3.2.7) lib/active_support/callbacks.rb:81:in `run_callbacks'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/callbacks.rb:26:in `run_paperclip_callbacks'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/attachment.rb:392:in `post_process'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip/attachment.rb:107:in `assign'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/paperclip-70f0f1fea030/lib/paperclip.rb:196:in `block in has_attached_file'
activerecord (3.2.7) lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
activerecord (3.2.7) lib/active_record/attribute_assignment.rb:78:in `each'
activerecord (3.2.7) lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
activerecord (3.2.7) lib/active_record/base.rb:498:in `initialize'
activerecord (3.2.7) lib/active_record/persistence.rb:44:in `new'
activerecord (3.2.7) lib/active_record/persistence.rb:44:in `create'
app/controllers/photography_controller.rb:23:in `create'
actionpack (3.2.7) lib/action_controller/metal/implicit_render.rb:4: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__403597772__process_action__67609296__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:35: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__122749671__call__530674861__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'
PhotographyController:
def create
#photo = Photo.create(params[:photo])
end
And finally, my form partial may be of some help:
<%= form_for #photo, :url => { :controller => 'photography', :action => 'create'}, :html => { :multipart => true } do |f| %>
<% if #photo.errors.any? %>
<div id="errorExplanation">
<h2><%= pluralize(#photo.errors.count, "error") %> prohibited
this photo from being saved:</h2>
<ul>
<% #photo.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :description %><br />
<%= f.text_area :description %>
</div>
<%= f.file_field :photo %>
<div class="actions">
<%= f.submit ('Upload Photo') %>
</div>
<% end %>
Thanks again.
I've ran into this error, and other similar ones as well, using paperclip. But I run my development environment on windows, and the latest version of paperclip uses the `file' command, which windows doesn't seem to like so much.
Hopefully this will be fixed soon, but for now I sidestepped the issue by using the last version of paperclip that works, namely 3.0.4.
If you're running on windows as well, just add this to your Gemfile:
gem 'paperclip', '3.0.4'
P.S. It might be worthwhile to try using 3.0.4 on development, and the latest version on production.
As the accepted answer suggests, this error can happen when Paperclip is unhappy for a variety of reasons.
In my case, I was upgrading from 4.1.1 to 6.1.0 and encountered this error.
The update required that I use the aws-sdk-s3 gem.
I resolved the error by setting s3_region in the paperclip config which is required when using aws-sdk-s3.
Ive been doing some research and I can't seem to find what Im doing wrong.
I have installed simple_form and nested_form gems but when I use either link_to_add or remove I get the same error.
Heres the code
/fields.html.erb
<%= render 'shared/error_messages', :object => f.object %>
<%= f.input :nombre_cliente, :label => 'Nombre del cliente:', :as => :string %>
<%= f.input :mail_cliente, :label => 'E-mail del cliente:', :as => :string %>
<%= f.input :empresa_cliente, :label => 'Empresa:', :as => :string %>
<%= f.input :confirmada, :label => 'Ha sido confirmada por el cliente.' %>
<%= f.input :confirmacion_cliente, :label => 'Fecha de confirmacion por el cliente:', :as => :date %>
<b>something here</b>
</br></br>
<%= f.simple_fields_for :producto_de_cotizacion do |productos| %>
<%= productos.input :nombre %>
<%= productos.input :descripcion %>
<%= productos.input :precio%>
<%= productos.link_to_remove("Eliminar producto") %>
<% end %>
<%= f.link_to_add "Agregar producto", :producto_de_cotizacion %>
Some of it is in spanish but I think its understandable
Here is the actual error Im getting:
undefined method `link_to_remove' for < SimpleForm::FormBuilder:0x9ccf37c>
That is the entirety of _fields.html.erb, but its being called by the new.html.erb and the edit.html.erb files which are basically identical, Ill post the edit file:
<h1>Agregar Cotizacion</h1>
<div id='admin_view'>
<%= simple_form_for #cotizacion, :html => {:multipart => true} do |f| %>
<%= render "fields", :f => f %>
<%= f.button :submit, 'Actualizar Cotizacion' %>
<% end%>
</div>
After changing it to simple_nested_form I get a new error:
undefined method `klass' for nil:NilClass
and heres the stack
activesupport (3.0.7) lib/active_support/whiny_nil.rb:48:in `method_missing'
/home/peanut/.rvm/gems/ruby-1.9.2-p180/bundler/gems/nested_form-57f32788f195/lib/nested_form/builder_mixin.rb:23:in `block in link_to_add'
/home/peanut/.rvm/gems/ruby-1.9.2-p180/bundler/gems/nested_form-57f32788f195/lib/nested_form/view_helper.rb:37:in `call'
/home/peanut/.rvm/gems/ruby-1.9.2-p180/bundler/gems/nested_form-57f32788f195/lib/nested_form/view_helper.rb:37:in `block in after_nested_form_callbacks'
/home/peanut/.rvm/gems/ruby-1.9.2-p180/bundler/gems/nested_form-57f32788f195/lib/nested_form/view_helper.rb:36:in `map'
/home/peanut/.rvm/gems/ruby-1.9.2-p180/bundler/gems/nested_form-57f32788f195/lib/nested_form/view_helper.rb:36:in `after_nested_form_callbacks'
/home/peanut/.rvm/gems/ruby-1.9.2-p180/bundler/gems/nested_form-57f32788f195/lib/nested_form/view_helper.rb:13:in `simple_nested_form_for'
app/views/cotizacions/edit.html.erb:3:in `_app_views_cotizacions_edit_html_erb__855809706_86735240_354753338'
actionpack (3.0.7) lib/action_view/template.rb:135:in `block in render'
activesupport (3.0.7) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.7) lib/action_view/template.rb:127:in `render'
actionpack (3.0.7) lib/action_view/render/rendering.rb:59:in `block in _render_template'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.7) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.7) lib/action_view/render/rendering.rb:56:in `_render_template'
actionpack (3.0.7) lib/action_view/render/rendering.rb:26:in `render'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:115:in `_render_template'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:109:in `render_to_body'
actionpack (3.0.7) lib/action_controller/metal/renderers.rb:47:in `render_to_body'
actionpack (3.0.7) lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:102:in `render_to_string'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:93:in `render'
actionpack (3.0.7) lib/action_controller/metal/rendering.rb:17:in `render'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.0.7) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/home/peanut/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
activesupport (3.0.7) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.0.7) lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:39:in `render'
meta-tags (1.2.4) lib/meta_tags/controller_helper.rb:28:in `render_with_meta_tags'
actionpack (3.0.7) lib/action_controller/metal/implicit_render.rb:14:in `default_render'
actionpack (3.0.7) lib/action_controller/metal/implicit_render.rb:6:in `send_action'
actionpack (3.0.7) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.7) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.7) lib/active_support/callbacks.rb:451:in `_run__761686272__process_action__750077467__callbacks'
activesupport (3.0.7) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.7) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.7) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.7) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.7) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.7) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.7) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.7) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:89: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.7) lib/action_dispatch/routing/route_set.rb:493:in `call'
warden (0.10.7) lib/warden/manager.rb:35:in `block in call'
warden (0.10.7) lib/warden/manager.rb:34:in `catch'
warden (0.10.7) lib/warden/manager.rb:34:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.4) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.7) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.7) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.7) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.7) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.7) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.7) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.4) lib/rack/sendfile.rb:106:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.7) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.4) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.7) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.4) lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.4) lib/rack/lock.rb:11:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.7) lib/rails/application.rb:168:in `call'
railties (3.0.7) lib/rails/application.rb:77:in `method_missing'
railties (3.0.7) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.4) lib/rack/content_length.rb:13:in `call'
rack (1.2.4) lib/rack/handler/webrick.rb:52:in `service'
/home/peanut/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/home/peanut/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/home/peanut/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Use :locals => { :f => f }
EDIT: Changing my answer.
I just realized you are using:
simple_form_for
Change that to
simple_nested_form_for
This allows you to use the nested_form options (link_to_add, link_to_remove, etc).
Cheers!
So I changed the new.html.erb and edit.html.erb to look like this:
<h1>Agregar Cotizacion</h1>
<div id='admin_view'>
<%= simple_nested_form_for #cotizacion, :html => {:multipart => true} do |f| %>
<%= render 'fields', :f => f %>
<%= f.button :submit, 'Agregar Cotizacion' %>
<% end%>
</div>
And I added this to the routes.rb file
resources :cotizacions do
resources :producto_de_cotizacions
end
resources :producto_de_cotizacions
Im not exactly sure how but this fixed the issue. Thanks a lot for your help. Cheers!
I have this error, solved by restarting server and adding this code to model:
accepts_nested_attributes_for :photos, :reject_if => :all_blank, :allow_destroy => true
I'm trying to use paperclip to handle file uploads in my Rails app. I'm currently running Paperclip 2.4.1 on Rails 3.0.9, running a WEBrick server on sqlite3.
The form worked fine before adding the file upload portion, but after following the quickstart instructions in the Paperclips docs (http://rdoc.info/gems/paperclip/2.4.1/file/README.md), upon form submission I get the following error:
undefined method `exitstatus' for nil:NilClass
at app/controllers/shows_controller.rb:62:in `create'
Here's the code for my model:
class Show < ActiveRecord::Base
has_many :pictures
has_attached_file :thumb,
:styles => { :thumb => "150x150>" },
:url => "/images/:id/thumb.:extension"
validates_attachment_presence :thumb
validates_presence_of :title
validates_presence_of :start_date
validates_presence_of :end_date
validates_presence_of :description
validates_presence_of :blurb
validates_presence_of :location
def self.current
where("shows.end_date > ?", Time.new).first
end
def self.thumb
image_tag self.thumb.url(:thumb)
end
end
The create method for my controller:
def create
#show = Show.create(params[:show])
respond_to do |format|
if #show.save
format.html { redirect_to(#show, :notice => 'Show was successfully created.') }
format.xml { render :xml => #show, :status => :created, :location => #show }
else
format.html { render :action => "new" }
format.xml { render :xml => #show.errors, :status => :unprocessable_entity }
end
end
(Line 62 is the #show = Show.create(params[:show] line))
My form:
<%= form_for #show, :html => {:multipart => true} do |f| %>
<% if #show.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#show.errors.count, "error") %> prohibited this show from being saved:</h2>
<ul>
<% #show.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :start_date %><br />
<%= f.date_select :start_date %>
</div>
<div class="field">
<%= f.label :end_date %><br />
<%= f.date_select :end_date %>
</div>
<div class="field">
<%= f.label :description %><br />
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.label :blurb %><br />
<%= f.text_field :blurb %>
</div>
<div class="field">
<%= f.label :location %><br />
<%= f.text_field :location %>
</div>
<div class="field">
<%= f.label :thumb %><br />
<%= f.file_field :thumb %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
And the full stack trace:
activesupport (3.0.9) lib/active_support/whiny_nil.rb:48:in `method_missing'
cocaine (0.2.0) lib/cocaine/command_line.rb:35:in `run'
paperclip (2.4.2) lib/paperclip.rb:102:in `run'
paperclip (2.4.2) lib/paperclip/geometry.rb:20:in `from_file'
paperclip (2.4.2) lib/paperclip/thumbnail.rb:35:in `initialize'
paperclip (2.4.2) lib/paperclip/processor.rb:33:in `new'
paperclip (2.4.2) lib/paperclip/processor.rb:33:in `make'
paperclip (2.4.2) lib/paperclip/attachment.rb:397:in `post_process_styles'
activemodel (3.0.9) lib/active_model/attribute_methods.rb:295:in `inject'
paperclip (2.4.2) lib/paperclip/attachment.rb:396:in `each'
paperclip (2.4.2) lib/paperclip/attachment.rb:396:in `inject'
paperclip (2.4.2) lib/paperclip/attachment.rb:396:in `post_process_styles'
activesupport (3.0.9) lib/active_support/ordered_hash.rb:139:in `each'
activesupport (3.0.9) lib/active_support/ordered_hash.rb:139:in `each'
paperclip (2.4.2) lib/paperclip/attachment.rb:392:in `post_process_styles'
paperclip (2.4.2) lib/paperclip/attachment.rb:386:in `post_process'
activesupport (3.0.9) lib/active_support/callbacks.rb:414:in `_run_thumb_post_process_callbacks'
activesupport (3.0.9) lib/active_support/callbacks.rb:94:in `send'
activesupport (3.0.9) lib/active_support/callbacks.rb:94:in `run_callbacks'
paperclip (2.4.2) lib/paperclip/callback_compatibility.rb:54:in `run_paperclip_callbacks'
paperclip (2.4.2) lib/paperclip/attachment.rb:385:in `post_process'
activesupport (3.0.9) lib/active_support/callbacks.rb:414:in `_run_post_process_callbacks'
activesupport (3.0.9) lib/active_support/callbacks.rb:94:in `send'
activesupport (3.0.9) lib/active_support/callbacks.rb:94:in `run_callbacks'
paperclip (2.4.2) lib/paperclip/callback_compatibility.rb:54:in `run_paperclip_callbacks'
paperclip (2.4.2) lib/paperclip/attachment.rb:384:in `post_process'
paperclip (2.4.2) lib/paperclip/attachment.rb:142:in `assign'
paperclip (2.4.2) lib/paperclip.rb:335:in `thumb='
activerecord (3.0.9) lib/active_record/base.rb:1564:in `send'
activerecord (3.0.9) lib/active_record/base.rb:1564:in `attributes='
activerecord (3.0.9) lib/active_record/base.rb:1560:in `each'
activerecord (3.0.9) lib/active_record/base.rb:1560:in `attributes='
activerecord (3.0.9) lib/active_record/base.rb:1412:in `initialize'
activerecord (3.0.9) lib/active_record/base.rb:502:in `new'
activerecord (3.0.9) lib/active_record/base.rb:502:in `create'
app/controllers/shows_controller.rb:62:in `create'
actionpack (3.0.9) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.9) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.9) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.9) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.9) lib/abstract_controller/callbacks.rb:18:in `process_action'
activesupport (3.0.9) lib/active_support/callbacks.rb:441:in `_run__918721632__process_action__524098549__callbacks'
activesupport (3.0.9) lib/active_support/callbacks.rb:410:in `send'
activesupport (3.0.9) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.9) lib/active_support/callbacks.rb:94:in `send'
activesupport (3.0.9) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.9) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
activesupport (3.0.9) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.9) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.9) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.9) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.9) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.9) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.9) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.9) lib/action_controller/metal.rb:178:in `action'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.9) 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:68: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.9) lib/action_dispatch/routing/route_set.rb:493:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.3) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.9) lib/active_record/query_cache.rb:32:in `call'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.9) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.9) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:46:in `call'
activesupport (3.0.9) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.3) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.9) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.3) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.9) 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.9) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.9) lib/rails/application.rb:168:in `call'
railties (3.0.9) lib/rails/application.rb:77:in `send'
railties (3.0.9) lib/rails/application.rb:77:in `method_missing'
railties (3.0.9) 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'
C:/Rails/Ruby1.8.7/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
C:/Rails/Ruby1.8.7/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
C:/Rails/Ruby1.8.7/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
C:/Rails/Ruby1.8.7/lib/ruby/1.8/webrick/server.rb:162:in `start'
C:/Rails/Ruby1.8.7/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
C:/Rails/Ruby1.8.7/lib/ruby/1.8/webrick/server.rb:95:in `start'
C:/Rails/Ruby1.8.7/lib/ruby/1.8/webrick/server.rb:92:in `each'
C:/Rails/Ruby1.8.7/lib/ruby/1.8/webrick/server.rb:92:in `start'
C:/Rails/Ruby1.8.7/lib/ruby/1.8/webrick/server.rb:23:in `start'
C:/Rails/Ruby1.8.7/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.9) lib/rails/commands/server.rb:65:in `start'
railties (3.0.9) lib/rails/commands.rb:30
railties (3.0.9) lib/rails/commands.rb:27:in `tap'
railties (3.0.9) lib/rails/commands.rb:27
script/rails:6:in `require'
script/rails:6
I wasn't able to find any instance of this error elsewhere relating to paperclip; It looks like its bubbling up from within Rails somewhere; any suggestions?
It seems that the command, that is run with cocaine is not correct. Have you configured paperclip's command path with Paperclip.options[:command_path] = "/usr/local/bin/" and installed ImageMagick in this path?
You can find out where ImageMagick is with which convert. This should yield the path to the convert binary of ImageMagick - in my case /usr/local/bin/convert
I just want to have ablility to edit class properties whish is not successor of ActiveRecord class.
Here is my class /app/model/entry.rb:
class Entry
attr_accessor :title, :body
end
Here is a controller:
class DiaryController < ApplicationController
def new
#entry = Entry.new
end
end
Here is a view:
<%= form_for(#entry) do |f| %>
<%= f.text_field :title %> <br />
<%= f.text_area :body %> <br />
<% end %>
I got the error message while I was opening form:
undefined method `model_name' for Entry:Class
Here is full stack:
Extracted source (around line #1):
1: <%= form_for(#entry) do |f| %>
2: <%= f.text_field :title %> <br />
3: <%= f.text_area :body %> <br />
4: <% end %>
Full trace:
activemodel (3.0.6) lib/active_model/naming.rb:95:in `model_name_from_record_or_class'
activemodel (3.0.6) lib/active_model/naming.rb:82:in `singular'
actionpack (3.0.6) lib/action_view/helpers/form_helper.rb:312:in `form_for'
app/views/diary/new.html.erb:1:in `_app_views_diary_new_html_erb___902027577_26033568_187052521'
actionpack (3.0.6) lib/action_view/template.rb:135:in `block in render'
activesupport (3.0.6) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.6) lib/action_view/template.rb:127:in `render'
actionpack (3.0.6) lib/action_view/render/rendering.rb:59:in `block in _render_template'
activesupport (3.0.6) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.6) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.6) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.6) lib/action_view/render/rendering.rb:56:in `_render_template'
actionpack (3.0.6) lib/action_view/render/rendering.rb:26:in `render'
actionpack (3.0.6) lib/abstract_controller/rendering.rb:115:in `_render_template'
actionpack (3.0.6) lib/abstract_controller/rendering.rb:109:in `render_to_body'
actionpack (3.0.6) lib/action_controller/metal/renderers.rb:47:in `render_to_body'
actionpack (3.0.6) lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
actionpack (3.0.6) lib/abstract_controller/rendering.rb:102:in `render_to_string'
actionpack (3.0.6) lib/abstract_controller/rendering.rb:93:in `render'
actionpack (3.0.6) lib/action_controller/metal/rendering.rb:17:in `render'
actionpack (3.0.6) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.0.6) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
c:/Ruby192/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
activesupport (3.0.6) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.0.6) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.0.6) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.0.6) lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (3.0.6) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.0.6) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.0.6) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (3.0.6) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.6) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.6) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.6) lib/active_support/callbacks.rb:436:in `_run__776311234__process_action__123531476__callbacks'
activesupport (3.0.6) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.6) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.6) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.6) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.6) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.6) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.6) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.6) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.6) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.6) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.6) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.6) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.6) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.6) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.6) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.6) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.6) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:68: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.6) lib/action_dispatch/routing/route_set.rb:493:in `call'
actionpack (3.0.6) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.6) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.2) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.6) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.6) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.6) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.6) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.6) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.6) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.6) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.6) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.6) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.6) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.6) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.2) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.6) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.6) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.6) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.2) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.6) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.2) lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.2) lib/rack/lock.rb:11:in `call'
actionpack (3.0.6) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.6) lib/rails/application.rb:168:in `call'
railties (3.0.6) lib/rails/application.rb:77:in `method_missing'
railties (3.0.6) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.2) lib/rack/content_length.rb:13:in `call'
rack (1.2.2) lib/rack/handler/webrick.rb:52:in `service'
c:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
c:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
c:/Ruby192/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Is the ability to edit class properties using the form_for-tag?
jdc answered this, but didn't show the actual implementation you requested. As jdc stated you need to include some ActiveModel modules, which will give your ruby class the features you need.
It looks like you need ActiveModel::Naming and ActiveModel::AttributeMethods.
class Entry
extend ActiveModel::Naming
include ActiveModel::AttributeMethods
end
The first line will give you model_name and the second line allow your model to function with the form helpers. There are other lines you can use: check the blog posted linked in jdc's answer or the Rails API.
More links with detailed information:
http://www.rubyinside.com/rails-3-0s-activemodel-how-to-give-ruby-classes-some-activerecord-magic-2937.html
http://railscasts.com/episodes/219-active-model
This blog entry should get you started:
http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/
You can include some of the modules ActiveRecord uses to get things like validation and serialization. Then, if you want something like a "save" method that doesn't go to the database, just create one. I did that for a contact model. It's not AR, just a plain old ruby object that pulls in some ActiveModel stuff for validation, provides some required methods, then the save method just fires an e-mail. I think there's even a mixin you can use to take care of that initialization stuff I'm doing to allow mass assignment on creation, but I haven't looked into it that closely. This object looks like an AR object to the front end, so the basic helpers all work.
class Contact
include ActiveModel::Validations
attr_accessor :id, :name, :email, :subject, :body
validates :name, :presence => true
validates :email, :presence => true
validates :subject, :presence => true
validates :body, :presence => true
def initialize(attributes = {})
attributes.each do |key, value|
self.send("#{key}=", value)
end
#attributes = attributes
end
def read_attribute_for_validation(key)
#attributes[key]
end
def to_key
end
def save
if self.valid?
ContactNotifier.website_contact(self).deliver
return true
end
false
end
end
It looks like the error your getting is from the following line in the form_helper.rb:
object_name = options[:as] || ActiveModel::Naming.param_key(object)
If you hardcode in :as => "Entry", you will get a tad farther. Or you could extend the class to respond to the method model_name. Here is the code in ActiveModel::Naming that calls model_name:
def self.model_name_from_record_or_class(record_or_class)
(record_or_class.is_a?(Class) ? record_or_class : convert_to_model(record_or_class).class).model_name
end
I could continue following the calls, but I'd recommend you follow it yourself. Eventually you will find a call that returns a hash of attributes and values that the form builder uses in form_for.
Just look through the rails source, see where your code throws an error, and extend your class to respond to the proper call. Keep doing it and your model will respond fine. You don't need to be an activerecord model to look, walk, and sound like an activerecord model.
I found this RailsCasts Episode#193 to be very helpful with what you're trying to do.
For one thing your entry model file should start like this:
class Entry < ActiveRecord::Base