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
Related
I've looked at all the other questions on SO that look similar but I can't find an answer that will help me.
I'm working on upgrading an app that was written a while ago and am struggling to get the image upload section of it working. The relevant bits of code are as follows:
photos_controller.rb:
def create
images = params[:an_image]
if !images.nil?
photos = []
images.each do |image|
photo = #trip.photos.build(:user => current_user, :trip => #trip, :image => image)
if photo.save
p 'saving ok'
photos << photo
else
p 'ERROR saving'
end
end
add_news('created_multiple', photos.first, {:photo_ids => photos.collect(&:id)})
flash[:notice] = "Your photos were updated successfully!"
redirect_to #trip
else
#photo.user = current_user
#photo.trip = #trip
if #photo.update_attributes(params[:photo]) || params[:photo][:an_image]
add_news('created', #photo)
redirect_to trip_photos_url(#photo.trip)
else
render :edit
end
end
end
photo.rb:
def an_image=(file)
self.trip.photos.create(:image => file)
end
attr_accessor :an_image
# Photo image
if Rails.env.test?
has_attached_file :image, :path => "/tmp/:attachment-:id-:style.:extension"
else
has_attached_file :image,
# 200 x 160 for news
:styles => {
:list => "270x200>",
:feed_item => "75x60>",
:map => "30x30#",
:homepage => "160x110#",
:normal => "300x500",
:tiny => "20x20#"
},
:processors => [:auto_orient, :thumbnail],
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:bucket => "saild-production",
:convert_options => {:map => '-bordercolor white -compose over -border 2'}
end
and photos/new.html.erb:
<div id="content-four">
<h1>Upload photos to <%= #trip.name %></h1>
<%= form_tag trip_photos_path(#trip), :multipart => true %>
<form id="post-photo" action="#">
<fieldset class="multiple-uploads">
Add more files<br>
<%= file_field_tag :an_image, :class => 'file-upload' %>
<script type="text/javascript">
$('.duplicate').click(function() {
$('.file-upload:first').clone().appendTo($('.multiple-uploads'))
})
</script>
</fieldset>
<fieldset>
<input type="submit" class="submit button" value="Publish"/>
</fieldset>
</form>
</div>
But when I try to upload a file I keep getting this error:
NoMethodError (undefined method `each' for #<ActionDispatch::Http::UploadedFile:0x007f971263b860>):
app/controllers/photos_controller.rb:33:in `create'
actionpack (3.0.7) lib/action_controller/metal/implicit_render.rb:5: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:461:in `_run__1507672816926971504__process_action__674209566928286804__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:75: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'
hoptoad_notifier (2.4.11) lib/hoptoad_notifier/rack.rb:27:in `call'
sass (3.4.12) lib/sass/plugin/rack.rb:54: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.8) 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.8) lib/rack/sendfile.rb:106:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
airbrake (4.1.0) lib/airbrake/rails/middleware.rb:13: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.8) 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.8) lib/rack/lock.rb:13:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.8) lib/rack/lock.rb:13:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/static.rb:30:in `call'
airbrake (4.1.0) lib/airbrake/user_informer.rb:16:in `_call'
airbrake (4.1.0) lib/airbrake/user_informer.rb:12:in `call'
hoptoad_notifier (2.4.11) lib/hoptoad_notifier/user_informer.rb:12: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.8) lib/rack/content_length.rb:13:in `call'
rack (1.2.8) lib/rack/handler/webrick.rb:52:in `service'
/Users/camillavk/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/Users/camillavk/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/Users/camillavk/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
What I think the code is trying to do is create an array of the images that are uploaded and then .build(which I've never come across -> I assume it is like .create?) with them individually, but it doesn't seem to want to put the uploaded files into an array...
Does anyone know how I can fix this?
(I'm running Rails 3.0.7 and Ruby 1.9.3)
Your problem is that params[:an_image] is a single object, and you call .each on it as if it was an array.
I've not tried this with file data before, but try changing the name attribute of the file_field_tag to have square brackets at the end, like
file_field_tag "an_image[]"
When you have [] at the end of the name attribute, then the values from all inputs with the same name attribute will be collected together into an array. Might be as simple as that...on the other hand, there might be something about how the multipart data is structured which prevents this.
Another tip, if you have to deal with a variable that might be an array or a single object, is to wrap it in an array, and then call flatten on it. eg
#turns foos into an array, whether it is a single object or an array already
foos = [foos].flatten
Now you can do foos.each, safe in the knowledge that it will always be an array.
Also - tail your development.log file when your form submits and you can see what's in params, and compare it to what your code is expecting.
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.
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
I'm trying to set up Authlogic as my default authentication system. I want the user to be able to log in using either their username or email. To accomplish this, I did the following:
app/model/user.rb:
class User < ActiveRecord::Base
#add authlogic authentications
acts_as_authentic do |c|
c.find_by_login_method :find_by_username_or_email
end
attr_accessible :username, :email, :password, :password_confirmation
validates :username, :presence => true,
:length => { :within => 3..20 },
:uniqueness => true,
:format => { :with => /\A[a-z0-9][a-z0-9\-]+[a-z0-9]\z/ }
validates :email, :presence => true,
:format => { :with => /\A[\w+\-.]+#[a-z\d\-.]+\.[a-z]+\z/i },
:uniqueness => { :case_sensative => false },
:length => { :maximum => 255 }
validates :password, :presence => true,
:confirmation => true,
:length => { :within => 6..40 }
def self.find_by_username_or_email(username_or_email)
find_by_username(username_or_email) || find_by_email(username_or_email)
end
end
app/model/session.rb:
class Session < Authlogic::Session::Base
end
app/controller/sessions_controller.rb:
class SessionsController < ApplicationController
before_filter :require_no_user, :only => [:new, :create]
before_filter :require_user, :only => :destroy
def new
#session = Session.new
end
def create
username = User.find_by_email(params[:session][:username_or_email]).username
username ||= params[:session][:username_or_email]
#session = Session.new(params[:session])
if #session.save
flash[:notice] = "Login successful!"
redirect_back_or_default :users
else
render :action => :new
end
end
def destroy
current_session.destroy
redirect_back_or_default new_session_url
end
end
app/views/sessions/new.html.erb:
<h1>Sign In</h1>
<%= render 'login_form' %>
app/views/sessions/_login_form.html.erb:
<%= form_for #session do |f| %>
<div class="field">
<%= f.label 'Username or Email' %><br />
<%= f.text_field :login %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<div class="actions">
<%= f.submit "Sign In", :class => "button" %>
</div>
<% end %>
config/routes.rb:
Test::Application.routes.draw do
resources :users
resources :sessions, :only => :create
match '/signup', :to => 'users#new'
match '/signin', :to => 'sessions#new', :as => :signin
match '/signout', :to => 'sessions#destroy', :as => :signout
end
When I run the rails server and try to connect to http://localhost:3000/signin, it gives the following error:
undefined method `login_field' for Object:Class
The full stack trace is as follows:
authlogic (3.0.3) lib/authlogic/session/password.rb:90:in `login_field'
authlogic (3.0.3) lib/authlogic/session/password.rb:213:in `login_field'
authlogic (3.0.3) lib/authlogic/session/password.rb:118:in `initialize'
authlogic (3.0.3) lib/authlogic/session/activation.rb:48:in `initialize'
authlogic (3.0.3) lib/authlogic/session/klass.rb:64:in `initialize'
authlogic (3.0.3) lib/authlogic/session/scopes.rb:79:in `initialize'
authlogic (3.0.3) lib/authlogic/session/persistence.rb:37:in `new'
authlogic (3.0.3) lib/authlogic/session/persistence.rb:37:in `find'
app/controllers/application_controller.rb:15:in `current_session'
app/controllers/application_controller.rb:20:in `current_user'
app/controllers/application_controller.rb:33:in `require_no_user'
activesupport (3.0.7) lib/active_support/callbacks.rb:447:in `_run__2106190539632311804__process_action__1284228636937718599__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: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.7) lib/action_dispatch/routing/route_set.rb:493:in `call'
sass (3.1.1) lib/sass/plugin/rack.rb:54: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.2) 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.2) lib/rack/sendfile.rb:107: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.2) 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.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.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.2) lib/rack/content_length.rb:13:in `call'
rack (1.2.2) lib/rack/handler/webrick.rb:52:in `service'
/Users/helixed/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/helixed/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/helixed/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
I don't really understand why this is happening. If I'm using find_by_login_method, then why does Authlogic even need login_field?
Update
I updated my code to match Olivier L's answer. The controller isn't working, but I think it's a lot closer.
app/models/user.rb:
class User < ActiveRecord::Base
#add authlogic authentications
acts_as_authentic do |c|
c.session_class = Session
c.find_by_login_method :find_by_username_or_email
end
attr_accessible :username, :email, :password, :password_confirmation
validates :username, :presence => true,
:length => { :within => 3..20 },
:uniqueness => true,
:format => { :with => /\A[a-z0-9][a-z0-9\-]+[a-z0-9]\z/ }
validates :email, :presence => true,
:format => { :with => /\A[\w+\-.]+#[a-z\d\-.]+\.[a-z]+\z/i },
:uniqueness => { :case_sensative => false },
:length => { :maximum => 255 }
validates :password, :presence => true,
:confirmation => true,
:length => { :within => 6..40 }
def self.find_by_username_or_email(username_or_email)
find_by_username(username_or_email) || find_by_email(username_or_email)
end
end
app/models/session.rb:
class Session < Authlogic::Session::Base
authenticate_with User
end
I'm now getting the error:
undefined method `find_by_login_method' for #<Class:0x00000101a77ba8>
Here's the application trace:
activerecord (3.0.7) lib/active_record/base.rb:984:in `method_missing'
app/models/user.rb:30:in `block in <class:User>'
authlogic (3.0.3) lib/authlogic/acts_as_authentic/base.rb:36:in `acts_as_authentic'
app/models/user.rb:28:in `<class:User>'
app/models/user.rb:25:in `<top (required)>'
activesupport (3.0.7) lib/active_support/dependencies.rb:454:in `load'
activesupport (3.0.7) lib/active_support/dependencies.rb:454:in `block in load_file'
activesupport (3.0.7) lib/active_support/dependencies.rb:596:in `new_constants_in'
activesupport (3.0.7) lib/active_support/dependencies.rb:453:in `load_file'
activesupport (3.0.7) lib/active_support/dependencies.rb:340:in `require_or_load'
activesupport (3.0.7) lib/active_support/dependencies.rb:491:in `load_missing_constant'
activesupport (3.0.7) lib/active_support/dependencies.rb:183:in `block in const_missing'
activesupport (3.0.7) lib/active_support/dependencies.rb:181:in `each'
activesupport (3.0.7) lib/active_support/dependencies.rb:181:in `const_missing'
activesupport (3.0.7) lib/active_support/dependencies.rb:503:in `load_missing_constant'
activesupport (3.0.7) lib/active_support/dependencies.rb:183:in `block in const_missing'
activesupport (3.0.7) lib/active_support/dependencies.rb:181:in `each'
activesupport (3.0.7) lib/active_support/dependencies.rb:181:in `const_missing'
app/models/session.rb:2:in `<class:Session>'
app/models/session.rb:1:in `<top (required)>'
activesupport (3.0.7) lib/active_support/dependencies.rb:454:in `load'
activesupport (3.0.7) lib/active_support/dependencies.rb:454:in `block in load_file'
activesupport (3.0.7) lib/active_support/dependencies.rb:596:in `new_constants_in'
activesupport (3.0.7) lib/active_support/dependencies.rb:453:in `load_file'
activesupport (3.0.7) lib/active_support/dependencies.rb:340:in `require_or_load'
activesupport (3.0.7) lib/active_support/dependencies.rb:491:in `load_missing_constant'
activesupport (3.0.7) lib/active_support/dependencies.rb:183:in `block in const_missing'
activesupport (3.0.7) lib/active_support/dependencies.rb:181:in `each'
activesupport (3.0.7) lib/active_support/dependencies.rb:181:in `const_missing'
activesupport (3.0.7) lib/active_support/dependencies.rb:503:in `load_missing_constant'
activesupport (3.0.7) lib/active_support/dependencies.rb:183:in `block in const_missing'
activesupport (3.0.7) lib/active_support/dependencies.rb:181:in `each'
activesupport (3.0.7) lib/active_support/dependencies.rb:181:in `const_missing'
app/controllers/application_controller.rb:15:in `current_session'
app/controllers/application_controller.rb:20:in `current_user'
app/controllers/application_controller.rb:33:in `require_no_user'
activesupport (3.0.7) lib/active_support/callbacks.rb:447:in `_run__1226739957950205446__process_action__742106135127651722__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: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.7) lib/action_dispatch/routing/route_set.rb:493:in `call'
sass (3.1.1) lib/sass/plugin/rack.rb:54: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.2) 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.2) lib/rack/sendfile.rb:107: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.2) 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.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.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.2) lib/rack/content_length.rb:13:in `call'
rack (1.2.2) lib/rack/handler/webrick.rb:52:in `service'
/Users/helixed/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/helixed/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/helixed/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Edit: ok, I found this other question which is basically the same as yours. His accepted answer would indicate you need to do this:
class Session < Authlogic::Session::Base
authenticate_with User
end
class User < ActiveRecord::Base
acts_as_authentic do |c|
c.session_class = Session
c.find_by_login_method :find_by_username_or_email
end
end
Look here for a good way to implement multi-login-field authentication.
Just in case the link ever becomes broken, here's what Michael Cindric suggests in his blog (edited to use your classes' and fields' names):
class Session < Authlogic::Session::Base
find_by_login_method :find_by_username_or_email
end
class User < ActiveRecord::Base
def self.find_by_username_or_email(login)
find_by_username(login) || find_by_email(login)
end
end