I have a problem with ActiveAdmin using Ruby ruby 1.9.2p290 and Ruby on Rails 3.2.1.
I used this wiki page to setup the resource for the AdminUsers that works perfectly: Your First Admin Resource: AdminUser
After that I wanted to create the resource for my project model. The migrations for that looks like this:
class CreateProjects < ActiveRecord::Migration
def change
create_table :projects do |t|
t.string :name
t.text :description
t.boolean :isactive
t.timestamps
end
end
end
class AddSlugToProjects < ActiveRecord::Migration
def change
add_column :projects, :slug, :string
add_index :projects, :slug
end
end
My project model:
class Project < ActiveRecord::Base
scope :isactive, :conditions => ["isactive = ?",true]
extend FriendlyId
friendly_id :name, use: [:slugged, :history]
attr_accessible :name, :description, :isactive
end
And that's the project_controller:
class ProjectsController < ApplicationController
def index
#
# #projects gets filled in application_controller to be always
# available for the twitter bootstrap navbar
# #projects = Project.isactive.find(:all, :order => 'LOWER(name) asc')
#
end
def show
#project = Project.isactive.find(params[:id])
if request.path != project_path(#project)
redirect_to #project, :status => :moved_permanently
end
end
end
The admin/projects.rb is currently 'empty'
ActiveAdmin.register Project do
end
And after all that, everything I get is the following error:
Started GET "/admin/projects" for 192.168.0.2 at 2012-02-21 20:58:49 +0100
Processing by Admin::ProjectsController#index as HTML
Project Load (0.1ms) SELECT "projects".* FROM "projects" WHERE (isactive = 't') ORDER BY LOWER(name) asc
AdminUser Load (0.1ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = 2 LIMIT 1
Rendered /home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.1/app/views/active_admin/resource/index.html.arb (11.7ms)
Completed 500 Internal Server Error in 54ms
ActionView::Template::Error (undefined method `reorder' for #<Array:0xa3ecd44>):
1: render renderer_for(:index)
activeadmin (0.4.1) lib/active_admin/views/pages/index.rb:41:in `items_in_collection?'
activeadmin (0.4.1) lib/active_admin/views/pages/index.rb:20:in `main_content'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:116:in `block (2 levels) in build_main_content_wrapper'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:68:in `block in build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:96:in `with_current_dom_context'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:67:in `build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:77:in `insert_tag'
activeadmin (0.4.1) lib/active_admin/arbre/html/element.rb:17:in `div'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:115:in `block in build_main_content_wrapper'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:68:in `block in build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:96:in `with_current_dom_context'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:67:in `build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:77:in `insert_tag'
activeadmin (0.4.1) lib/active_admin/arbre/html/element.rb:17:in `div'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:114:in `build_main_content_wrapper'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:98:in `block in build_page_content'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:68:in `block in build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:96:in `with_current_dom_context'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:67:in `build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:77:in `insert_tag'
activeadmin (0.4.1) lib/active_admin/arbre/html/element.rb:17:in `div'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:97:in `build_page_content'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:41:in `block (2 levels) in build_page'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:68:in `block in build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:96:in `with_current_dom_context'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:67:in `build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:77:in `insert_tag'
activeadmin (0.4.1) lib/active_admin/arbre/html/element.rb:17:in `div'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:38:in `block in build_page'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:96:in `with_current_dom_context'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:37:in `build_page'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:10:in `build'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:63:in `build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:77:in `insert_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:41:in `method_missing'
activeadmin (0.4.1) lib/active_admin/view_helpers/renderer_helper.rb:21:in `render'
activeadmin (0.4.1) app/views/active_admin/resource/index.html.arb:1:in `__home_eins____rbenv_versions_______p____lib_ruby_gems_______gems_activeadmin_______app_views_active_admin_resource_index_html_arb___523541447_100786690'
actionpack (3.2.1) lib/action_view/template.rb:143:in `block in render'
activesupport (3.2.1) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.1) lib/action_view/template.rb:141:in `render'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:41:in `block (2 levels) in render_template'
actionpack (3.2.1) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.1) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:40:in `block in render_template'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:48:in `render_with_layout'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:39:in `render_template'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:12:in `render'
actionpack (3.2.1) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.1) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:109:in `_render_template'
actionpack (3.2.1) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.1) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.1) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.1) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.1) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
activesupport (3.2.1) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.1) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:39:in `render'
activeadmin (0.4.1) lib/active_admin/resource_controller/actions.rb:13:in `block (2 levels) in index'
actionpack (3.2.1) lib/action_controller/metal/responder.rb:229:in `call'
actionpack (3.2.1) lib/action_controller/metal/responder.rb:229:in `default_render'
actionpack (3.2.1) lib/action_controller/metal/responder.rb:160:in `to_html'
responders (0.6.5) lib/responders/flash_responder.rb:93:in `to_html'
actionpack (3.2.1) lib/action_controller/metal/responder.rb:153:in `respond'
actionpack (3.2.1) lib/action_controller/metal/responder.rb:146:in `call'
actionpack (3.2.1) lib/action_controller/metal/mime_responds.rb:238:in `respond_with'
inherited_resources (1.3.0) lib/inherited_resources/actions.rb:7:in `index'
activeadmin (0.4.1) lib/active_admin/resource_controller/actions.rb:11:in `index'
actionpack (3.2.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.1) lib/active_support/callbacks.rb:469:in `_run__639476650__process_action__1068992826__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
activerecord (3.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.1) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `dispatch'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:30:in `call'
journey (1.0.1) lib/journey/router.rb:68:in `block in call'
journey (1.0.1) lib/journey/router.rb:56:in `each'
journey (1.0.1) lib/journey/router.rb:56:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:589:in `call'
sass (3.1.15) lib/sass/plugin/rack.rb:54:in `call'
warden (1.1.1) lib/warden/manager.rb:35:in `block in call'
warden (1.1.1) lib/warden/manager.rb:34:in `catch'
warden (1.1.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.1) 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.1) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.1) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__471556791__call__937320005__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.1) 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.1) 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.1) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.2.1) lib/rails/engine.rb:479:in `call'
railties (3.2.1) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Rendered /home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (5.1ms)
Rendered /home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.1ms)
Rendered /home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (9.8ms)
And I have no idea what the problem is...
Ah, I've found the solution.
I don't know exactly why the error happened but I had to change my application_controller.
In the application_controller I fetched all projects to #projects:
before_filter :getActiveProjects
protected
def getActiveProjects
#projects = Project.isactive.find(:all, :order => 'LOWER(name) asc')
end
That was confusing ActiveAdmin. After I changed that to
before_filter :getActiveProjects
protected
def getActiveProjects
#projects_all = Project.isactive.find(:all, :order => 'LOWER(name) asc')
end
and projects_controller index action to
def index
#projects = #projects_all
end
everything worked fine ;)
An easier solution is to just skip the filter in the particular active admin controller:
ActiveAdmin.register Project do
controller do
skip_before_filter :getActiveProjects
end
end
The active admin make special processing of #resource variables. Where resource is correponding class name passed to register method. So for code:
ActiveAdmin.register Project do
end
name of variable is
`#project`
We must not assign value to variable with such name. Also such varibles may be object of ActiveRecord::Relation class. And how #Oliver write the name like #projects_all is good choice. The using of skip_before_filter is solve the problem too.
One crafty thing need to check. The controller of resource may not have any filters. The controller of resource may not exists at all. What is the filter name to put to skip_before_filter? And where is such filters? The default application controller is used anyway. The filter may be installed at main application controller. The error message of this problem is not informative at all. So need to check application controller for installed filters too.
Related
Im making an application in rails and my upload is throwing an error. Here are the details. My photos_controller.rb
def create
#photo = Photo.new(params[:photo])
respond_to do |format|
if #photo.save
format.html { redirect_to #photo, notice: 'Photo was successfully created.' }
format.json { render json: #photo, status: :created, location: #photo }
else
format.html { render action: "new" }
format.json { render json: #photo.errors, status: :unprocessable_entity }
end
end
end
my form
<%= f.file_field :binary_data %>
<%= f.submit %>
database model
t.string :photon
t.column :lat, :string
t.column :lon, :string
t.column :pname, :string
t.column :uname, :string
t.column :content_type, :string
t.column :filename, :string
t.column :binary_data, :binary
t.timestamps
I tried some ways which was mentioned in some blogs. None of them worked.
Here is the full trace
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:25:in `block in initialize'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `yield'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `default'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `accept'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:447:in `block in dump_ivars'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:445:in `each'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:445:in `dump_ivars'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:124:in `visit_Object'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `accept'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:66:in `push'
/usr/lib/ruby/1.9.1/psych.rb:242:in `dump'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/quoting.rb:38:in `quote'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:203:in `quote'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/database_statements.rb:8:in `block in to_sql'
arel (3.0.3) lib/arel/visitors/bind_visitor.rb:17:in `call'
arel (3.0.3) lib/arel/visitors/bind_visitor.rb:17:in `visit_Arel_Nodes_BindParam'
arel (3.0.3) lib/arel/visitors/visitor.rb:19:in `visit'
arel (3.0.3) lib/arel/visitors/to_sql.rb:111:in `block in visit_Arel_Nodes_Values'
arel (3.0.3) lib/arel/visitors/to_sql.rb:109:in `map'
arel (3.0.3) lib/arel/visitors/to_sql.rb:109:in `visit_Arel_Nodes_Values'
arel (3.0.3) lib/arel/visitors/visitor.rb:19:in `visit'
arel (3.0.3) lib/arel/visitors/to_sql.rb:74:in `visit_Arel_Nodes_InsertStatement'
arel (3.0.3) lib/arel/visitors/visitor.rb:19:in `visit'
arel (3.0.3) lib/arel/visitors/visitor.rb:5:in `accept'
arel (3.0.3) lib/arel/visitors/to_sql.rb:19:in `accept'
arel (3.0.3) lib/arel/visitors/bind_visitor.rb:11:in `accept'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `to_sql'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/database_statements.rb:89:in `insert'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
activerecord (3.2.2) lib/active_record/relation.rb:66:in `insert'
activerecord (3.2.2) lib/active_record/persistence.rb:363:in `create'
activerecord (3.2.2) lib/active_record/timestamp.rb:57:in `create'
activerecord (3.2.2) lib/active_record/callbacks.rb:268:in `block in create'
activesupport (3.2.2) lib/active_support/callbacks.rb:403:in `_run__4454296851553403224__create__1976589364162331536__callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.2) lib/active_support/callbacks.rb:385:in `_run_create_callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
activerecord (3.2.2) lib/active_record/callbacks.rb:268:in `create'
activerecord (3.2.2) lib/active_record/persistence.rb:344:in `create_or_update'
activerecord (3.2.2) lib/active_record/callbacks.rb:264:in `block in create_or_update'
activesupport (3.2.2) lib/active_support/callbacks.rb:403:in `_run__4454296851553403224__save__1976589364162331536__callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.2) lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
activerecord (3.2.2) lib/active_record/callbacks.rb:264:in `create_or_update'
activerecord (3.2.2) lib/active_record/persistence.rb:84:in `save'
activerecord (3.2.2) lib/active_record/validations.rb:50:in `save'
activerecord (3.2.2) lib/active_record/attribute_methods/dirty.rb:22:in `save'
activerecord (3.2.2) lib/active_record/transactions.rb:241:in `block (2 levels) in save'
activerecord (3.2.2) lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
activerecord (3.2.2) lib/active_record/transactions.rb:208:in `transaction'
activerecord (3.2.2) lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
activerecord (3.2.2) lib/active_record/transactions.rb:241:in `block in save'
activerecord (3.2.2) lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
activerecord (3.2.2) lib/active_record/transactions.rb:240:in `save'
app/controllers/photos_controller.rb:47:in `block in create'
actionpack (3.2.2) lib/action_controller/metal/mime_responds.rb:278:in `call'
actionpack (3.2.2) lib/action_controller/metal/mime_responds.rb:278:in `retrieve_collector_from_mimes'
actionpack (3.2.2) lib/action_controller/metal/mime_responds.rb:194:in `respond_to'
app/controllers/photos_controller.rb:46:in `create'
actionpack (3.2.2) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.2) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.2) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.2) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.2) lib/active_support/callbacks.rb:414:in `_run__1057882058708114548__process_action__3391181575290593173__callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.2) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.2) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.2) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.2) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.2) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.2) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.2) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.2) lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
activerecord (3.2.2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.2) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.2) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.2) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.2) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.2) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:67:in `call'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:67:in `dispatch'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:30:in `call'
/usr/lib/ruby/vendor_ruby/journey/router.rb:68:in `block in call'
/usr/lib/ruby/vendor_ruby/journey/router.rb:56:in `each'
/usr/lib/ruby/vendor_ruby/journey/router.rb:56:in `call'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:594:in `call'
actionpack (3.2.2) 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.2) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.2) 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.2) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.2) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in `_run__255478243604444547__call__1976589364162331536__callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.2) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.2) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.2) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.2) 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.2) 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.2) lib/action_dispatch/middleware/static.rb:61:in `call'
railties (3.2.2) lib/rails/engine.rb:479:in `call'
railties (3.2.2) lib/rails/application.rb:220:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.2) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
parameters
{"utf8"=>"✓",
"authenticity_token"=>"1zvkibcE9YuaT2sR2ofHx06MlpH7JtK7QiK/sExTNVY=",
"photo"=>{"binary_data"=>#<ActionDispatch::Http::UploadedFile:0x007fdc144411a8 #original_filename="1.jpg",
#content_type="image/jpeg",
#headers="Content-Disposition: form-data; name=\"photo[binary_data]\"; filename=\"1.jpg\"\r\nContent-Type: image/jpeg\r\n",
#tempfile=#<File:/tmp/RackMultipart20140417-28258-142dwwo>>},
"commit"=>"Create Photo"}
server log
Started POST "/photos" for 127.0.0.1 at 2014-04-17 03:21:40 +0530
Processing by PhotosController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"1zvkibcE9YuaT2sR2ofHx06MlpH7JtK7QiK/sExTNVY=", "photo"=>{"binary_data"=>#<ActionDispatch::Http::UploadedFile:0x007fdc144411a8 #original_filename="1.jpg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"photo[binary_data]\"; filename=\"1.jpg\"\r\nContent-Type: image/jpeg\r\n", #tempfile=#<File:/tmp/RackMultipart20140417-28258-142dwwo>>}, "commit"=>"Create Photo"}
(0.1ms) BEGIN
(0.2ms) ROLLBACK
Completed 500 Internal Server Error in 23ms
NoMethodError (undefined method `name' for nil:NilClass):
app/controllers/photos_controller.rb:47:in `block in create'
app/controllers/photos_controller.rb:46:in `create'
I am trying to implement a form with a many to many association (with :through) using active_admin. I am receiving undefined method `call' for nil:NilClass error message.
I am new to ruby and rails.
My models:
article.rb
class Article < ActiveRecord::Base
has_many :tagged_articles
has_many :tags, :through => :tagged_articles, :source => :tag, :class_name => TaggedArticle
accepts_nested_attributes_for :tags
end
tagged_article.rb
class TaggedArticle < ActiveRecord::Base
belongs_to :article
belongs_to :tag
end
tag.rb
class Tag < ActiveRecord::Base
has_many :tagged_articles
has_many :articles, :through => :tagged_articles
end
view
_form.html
<%= semantic_form_for #article, :html => {:id => "new_article",
:novalidate => "novalidate"} do |f| %>
app/admin/article.rb (active_admin file)
ActiveAdmin.register Article do
form partial: 'form'
form do |f|
f.has_many :tags, heading: 'Tags', allow_destroy: true, new_record: true
f.actions
end
show do
# renders app/views/admin/posts/_some_partial.html.erb
render 'preview'
end
#permit_params :title, :text,
# tags_attributes: [:name]
permit_params do
permitted = [:title, :text,
tags_attributes: [:name]]
# permitted << :other if resource.something?
permitted
end
end
I get this error (when opening the form)
Application trace
Extracted source (around line #1):
1
insert_tag renderer_for(:new)
app/admin/article.rb:6:in `block (2 levels) in <top (required)>'
Full trace
Application Trace | Framework Trace | Full Trace
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/form_builder.rb:61:in `block in has_many'
formtastic (2.3.0.rc2) lib/formtastic/helpers/inputs_helper.rb:375:in `call'
formtastic (2.3.0.rc2) lib/formtastic/helpers/inputs_helper.rb:375:in `block (2 levels) in inputs_for_nested_attributes'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/form_builder.rb:143:in `block in field_set_and_list_wrapping'
actionpack (4.0.2) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
actionpack (4.0.2) lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
actionpack (4.0.2) lib/action_view/helpers/capture_helper.rb:38:in `capture'
formtastic (2.3.0.rc2) lib/formtastic/helpers/fieldset_wrapper.rb:32:in `field_set_and_list_wrapping'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/form_builder.rb:142:in `field_set_and_list_wrapping'
formtastic (2.3.0.rc2) lib/formtastic/helpers/inputs_helper.rb:292:in `inputs'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/form_builder.rb:20:in `block in inputs'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/form_builder.rb:151:in `with_new_form_buffer'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/form_builder.rb:20:in `inputs'
formtastic (2.3.0.rc2) lib/formtastic/helpers/inputs_helper.rb:373:in `block in inputs_for_nested_attributes'
actionpack (4.0.2) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
actionpack (4.0.2) lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
actionpack (4.0.2) lib/action_view/helpers/capture_helper.rb:38:in `capture'
actionpack (4.0.2) lib/action_view/helpers/form_helper.rb:1864:in `block in fields_for_nested_model'
actionpack (4.0.2) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
actionpack (4.0.2) lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
actionpack (4.0.2) lib/action_view/helpers/capture_helper.rb:38:in `capture'
actionpack (4.0.2) lib/action_view/helpers/form_helper.rb:699:in `fields_for'
actionpack (4.0.2) lib/action_view/helpers/form_helper.rb:1863:in `fields_for_nested_model'
actionpack (4.0.2) lib/action_view/helpers/form_helper.rb:1849:in `block in fields_for_with_nested_attributes'
actionpack (4.0.2) lib/action_view/helpers/form_helper.rb:1847:in `each'
actionpack (4.0.2) lib/action_view/helpers/form_helper.rb:1847:in `fields_for_with_nested_attributes'
actionpack (4.0.2) lib/action_view/helpers/form_helper.rb:1521:in `fields_for'
formtastic (2.3.0.rc2) lib/formtastic/helpers/inputs_helper.rb:391:in `inputs_for_nested_attributes'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/form_builder.rb:176:in `block in js_for_has_many'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/form_builder.rb:151:in `with_new_form_buffer'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/form_builder.rb:176:in `js_for_has_many'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/form_builder.rb:99:in `block in has_many'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/form_builder.rb:160:in `block in without_wrapper'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/form_builder.rb:151:in `with_new_form_buffer'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/form_builder.rb:160:in `without_wrapper'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/form_builder.rb:90:in `has_many'
app/admin/article.rb:6:in `block (2 levels) in <top (required)>'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/views/pages/form.rb:23:in `instance_exec'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/views/pages/form.rb:23:in `block in main_content'
actionpack (4.0.2) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
actionpack (4.0.2) lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
actionpack (4.0.2) lib/action_view/helpers/capture_helper.rb:38:in `capture'
actionpack (4.0.2) lib/action_view/helpers/form_helper.rb:435:in `form_for'
formtastic (2.3.0.rc2) lib/formtastic/helpers/form_helper.rb:167:in `block in semantic_form_for'
formtastic (2.3.0.rc2) lib/formtastic/helpers/form_helper.rb:190:in `with_custom_field_error_proc'
formtastic (2.3.0.rc2) lib/formtastic/helpers/form_helper.rb:166:in `semantic_form_for'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/view_helpers/form_helper.rb:9:in `active_admin_form_for'
arbre (1.0.1) lib/arbre/element.rb:175:in `method_missing'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/views/pages/form.rb:22:in `main_content'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/views/pages/base.rb:83:in `block (2 levels) in build_main_content_wrapper'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:14:in `div'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/views/pages/base.rb:82:in `block in build_main_content_wrapper'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:14:in `div'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/views/pages/base.rb:81:in `build_main_content_wrapper'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/views/pages/base.rb:65:in `block in build_page_content'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:14:in `div'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/views/pages/base.rb:64:in `build_page_content'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/views/pages/base.rb:47:in `block (2 levels) in build_page'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:14:in `div'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/views/pages/base.rb:44:in `block in build_page'
arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/views/pages/base.rb:43:in `build_page'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/lib/active_admin/views/pages/base.rb:10:in `build'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:30:in `block in build_tag'
arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/app/views/active_admin/resource/new.html.arb:1:in `block in __home_javkhlan__rvm_gems_ruby_______bundler_gems_active_admin__ca___f__ab__app_views_active_admin_resource_new_html_arb__4076692881198465766_51912660'
arbre (1.0.1) lib/arbre/context.rb:45:in `instance_eval'
arbre (1.0.1) lib/arbre/context.rb:45:in `initialize'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/app/views/active_admin/resource/new.html.arb:1:in `new'
/home/javkhlan/.rvm/gems/ruby-2.1.0/bundler/gems/active_admin-9ca081f47ab4/app/views/active_admin/resource/new.html.arb:1:in `__home_javkhlan__rvm_gems_ruby_______bundler_gems_active_admin__ca___f__ab__app_views_active_admin_resource_new_html_arb__4076692881198465766_51912660'
actionpack (4.0.2) lib/action_view/template.rb:143:in `block in render'
activesupport (4.0.2) lib/active_support/notifications.rb:161:in `instrument'
actionpack (4.0.2) lib/action_view/template.rb:141:in `render'
actionpack (4.0.2) lib/action_view/renderer/template_renderer.rb:49:in `block (2 levels) in render_template'
actionpack (4.0.2) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (4.0.2) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.2) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.2) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (4.0.2) lib/action_view/renderer/template_renderer.rb:48:in `block in render_template'
actionpack (4.0.2) lib/action_view/renderer/template_renderer.rb:56:in `render_with_layout'
actionpack (4.0.2) lib/action_view/renderer/template_renderer.rb:47:in `render_template'
actionpack (4.0.2) lib/action_view/renderer/template_renderer.rb:17:in `render'
actionpack (4.0.2) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionpack (4.0.2) lib/action_view/renderer/renderer.rb:23:in `render'
actionpack (4.0.2) lib/abstract_controller/rendering.rb:127:in `_render_template'
actionpack (4.0.2) lib/action_controller/metal/streaming.rb:219:in `_render_template'
actionpack (4.0.2) lib/abstract_controller/rendering.rb:120:in `render_to_body'
actionpack (4.0.2) lib/action_controller/metal/rendering.rb:33:in `render_to_body'
actionpack (4.0.2) lib/action_controller/metal/renderers.rb:26:in `render_to_body'
actionpack (4.0.2) lib/abstract_controller/rendering.rb:97:in `render'
actionpack (4.0.2) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
activesupport (4.0.2) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/home/javkhlan/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
activesupport (4.0.2) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.0.2) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (4.0.2) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.0.2) lib/action_controller/metal/responder.rb:233:in `default_render'
actionpack (4.0.2) lib/action_controller/metal/responder.rb:161:in `to_html'
responders (1.0.0) lib/responders/flash_responder.rb:104:in `to_html'
actionpack (4.0.2) lib/action_controller/metal/responder.rb:154:in `respond'
actionpack (4.0.2) lib/action_controller/metal/responder.rb:147:in `call'
actionpack (4.0.2) lib/action_controller/metal/mime_responds.rb:330:in `respond_with'
inherited_resources (1.4.1) lib/inherited_resources/actions.rb:19:in `new'
actionpack (4.0.2) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.2) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.2) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.2) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.2) lib/active_support/callbacks.rb:433:in `_run__1569366334490291269__process_action__callbacks'
activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.2) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.2) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.2) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.2) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.2) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.2) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.2) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.2) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.2) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.2) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.2) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.2) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.2) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:680:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.2) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.2) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.2) lib/active_support/callbacks.rb:373:in `_run__782737588198479971__call__callbacks'
activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.2) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.2) lib/rails/engine.rb:511:in `call'
railties (4.0.2) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/home/javkhlan/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/home/javkhlan/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/home/javkhlan/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Any idea on how i can make it working?
I think that the reason for nilclass error was that there were no assigned fields for the nested form.
Adding
f.has_many :tags do |cf|
cf.input :tag, :label => "Tag"
end
solved the nilclass problem
In the end, the following code worked. And there was no need to wirte _form.html.erb in this particular case.
form do |f|
f.has_many :tags do |cf|
cf.input :tag, :label => "Tag"
end
f.actions
end
If you're using allow_destroy: true in the form fields, you also need to use it on accepts_nested_attributes_for.
class Article < ActiveRecord::Base
has_many :tagged_articles
has_many :tags, :through => :tagged_articles, :source => :tag, :class_name => TaggedArticle
accepts_nested_attributes_for :tags, allow_destroy: true
end
I have two models:
class Forum < ActiveRecord::Base
has_many :threads
end
class Thread < ActiveRecord::Base
belongs_to :forum, :dependent => :destroy
has_many :posts
end
In my view, I try this:
<%= #forum.name %>
<% #forum.threads.each do |thread| %>
<%= link_to thread.name, [#forum, thread], :class => "remote" %>
<% end %>
And I get this error on line #1:
undefined method `scoped' for Thread:Class
Any idea what's going on here? I've seen other users describe this problem, but it's typically because they've pluralized the has_many or singularized the belongs_to. As far as I can tell, my models are well-made. Please let me know what I'm doing wrong.
The full stack trace:
activerecord (3.2.9) lib/active_record/associations/association.rb:123:in `target_scope'
activerecord (3.2.9) lib/active_record/associations/association.rb:87:in `scoped'
activerecord (3.2.9) lib/active_record/associations/collection_association.rb:382:in `find_target'
activerecord (3.2.9) lib/active_record/associations/collection_association.rb:335:in `load_target'
C:in `load_target'
activerecord (3.2.9) lib/active_record/associations/collection_proxy.rb:87:in `method_missing'
app/views/forums/_show.html.erb:2:in `_app_views_forums__show_html_erb___1062139204_27502608'
actionpack (3.2.9) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.9) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.9) lib/action_view/template.rb:143:in `render'
actionpack (3.2.9) lib/action_view/renderer/partial_renderer.rb:265:in `render_partial'
actionpack (3.2.9) lib/action_view/renderer/partial_renderer.rb:238:in `block in render'
actionpack (3.2.9) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.9) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.9) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.9) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.9) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.9) lib/action_view/renderer/partial_renderer.rb:237:in `render'
actionpack (3.2.9) lib/action_view/renderer/renderer.rb:41:in `render_partial'
actionpack (3.2.9) lib/action_view/helpers/rendering_helper.rb:27:in `render'
app/views/forums/show.html.erb:1:in `_app_views_forums_show_html_erb___608144578_36161352'
actionpack (3.2.9) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.9) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.9) lib/action_view/template.rb:143:in `render'
actionpack (3.2.9) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
actionpack (3.2.9) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.9) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.9) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.9) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.9) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.9) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
actionpack (3.2.9) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
actionpack (3.2.9) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
actionpack (3.2.9) lib/action_view/renderer/template_renderer.rb:18:in `render'
actionpack (3.2.9) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.9) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.9) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.9) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.9) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.9) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.9) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.9) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.9) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.9) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.9) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
activesupport (3.2.9) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.9) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.9) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.9) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.9) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.2.9) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.2.9) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (3.2.9) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.9) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.9) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.9) lib/active_support/callbacks.rb:425:in `_run__271720943__process_action__435225614__callbacks'
activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.9) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.9) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.9) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.9) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.9) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.9) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.9) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.9) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.9) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.9) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.9) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.9) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.9) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.9) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.9) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.9) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.9) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.9) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.9) 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.9) lib/action_dispatch/routing/route_set.rb:601: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.9) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.9) 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.9) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.9) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `_run__598850227__call__514831618__callbacks'
activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.9) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.9) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.9) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.9) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.9) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.9) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.9) 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.9) 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.9) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.9) lib/rails/engine.rb:479:in `call'
railties (3.2.9) lib/rails/application.rb:223:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.9) 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'
The problem is caused by your model class name Thread, because it is also the name of a standard Ruby class.
When Rails tries to find the target class of the association it uses the internal class Thread (which has no scoped method) instead of your model class.
There a two solutions:
1. Rename the model (best solution)
class Topic < ActiveRecord::Base #Thread class
end
class Forum < ActiveRecord::Base
has_many :topics
end
This way you can still keep your original association names:
class Forum < ActiveRecord::Base
has_many :theads, class_name: 'Topic'
end
2. Put your Thread model in a module (works but might have unwanted side-effects)
class MyApp::Thread < ActiveRecord::Base
end
class Forum < ActiveRecord::Base
has_many :threads, class_name: 'MyApp::Thread'
end
You could also put all your models and controllers in a module. Rails looks for constants in the current module first, so your Thread class will be found first. This also has the advantage that you don't have to explicitly specify the class_name on your associations or in your controller actions.
class MyApp::Thread < ActiveRecord::Base
end
class MyApp::Forum < ActiveRecord::Base
has_many :threads # Works!
end
class MyApp::ThreadsController < ApplicationController
def show
#thread = Thread.find(params[:id]) # Works!
end
end
But you also have to change your routes.rb to account for the module and your input names in your views will all be prefixed with the module name, so even if this solution looks very clean, it might not be what you want.
Perhaps this construct: [#forum, thread] is making rails look for a nested resource in config/routes.rb such as
resources :forums do
resources :threads
end
I just tried out rails_admin and I ran into problems when saving strings containing umlauts (e.g. "ü, ö, ä ..."). The model is saved to the database, but the follow up screen fails.
incompatible character encodings: UTF-8 and ASCII-8BIT
Extracted source (around line #17):
14: = menu_for((#abstract_model ? (#object.try(:persisted?) ? :member : :collection) : :root), #abstract_model, #object)
15: = content_for :contextual_tabs
16: = yield
17:
18: %footer
19: %p © RailsAdmin 2012
I also tried to encode the string in utf8 using a before_save hook, but after pressing save the error is still there:
My Model
# encoding: utf-8
require 'carrierwave/orm/activerecord'
class Product < ActiveRecord::Base
mount_uploader :img_small, ProductImgSmallUploader
mount_uploader :img_large, ProductImgLargeUploader
attr_accessible :img_small, :img_small_cache, :remove_img_small
attr_accessible :img_large, :img_large_cache, :remove_img_large
attr_accessible :title_de, :title_en, :description_de, :description_en, :visible
before_save do
[:title_de,:title_en,:description_de,:description_en].each do |arg|
if self.try arg
self.send("#{arg}=", self.send(arg).encode('UTF-8'))
end
end
end
end
Any suggestions on how to fix it on my side? Or do i have to fork the gem?
Full Stacktrace
rails_admin (0.1.2) app/views/layouts/rails_admin/pjax.html.haml:17:in `_c___uby____lib_ruby_gems_______gems_rails_admin_______app_views_layouts_rails_admin_pjax_html_haml___1061959050_34768032'
actionpack (3.2.8) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.8) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.8) lib/action_view/template.rb:143:in `render'
actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
actionpack (3.2.8) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.8) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.8) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.8) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.8) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:18:in `render'
actionpack (3.2.8) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.8) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.8) lib/action_view/helpers/rendering_helper.rb:24:in `render'
haml (3.1.7) lib/haml/helpers/action_view_mods.rb:11:in `block in render_with_haml'
haml (3.1.7) lib/haml/helpers.rb:90:in `non_haml'
haml (3.1.7) lib/haml/helpers/action_view_mods.rb:11:in `render_with_haml'
rails_admin (0.1.2) app/views/layouts/rails_admin/application.html.haml:27:in `_c___uby____lib_ruby_gems_______gems_rails_admin_______app_views_layouts_rails_admin_application_html_haml___191072136_5393304'
actionpack (3.2.8) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.8) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.8) lib/action_view/template.rb:143:in `render'
actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:59:in `render_with_layout'
actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:18:in `render'
actionpack (3.2.8) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.8) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.8) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.8) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.8) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.8) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.8) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.8) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.8) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.8) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
c:/Ruby193/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
activesupport (3.2.8) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.8) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:39:in `render'
remotipart (1.0.2) lib/remotipart/render_overrides.rb:8:in `render'
rails_admin (0.1.2) lib/rails_admin/config/actions/index.rb:35:in `block (4 levels) in '
actionpack (3.2.8) lib/action_controller/metal/mime_responds.rb:196:in `call'
actionpack (3.2.8) lib/action_controller/metal/mime_responds.rb:196:in `respond_to'
rails_admin (0.1.2) lib/rails_admin/config/actions/index.rb:32:in `block (2 levels) in '
(eval):8:in `instance_eval'
(eval):8:in `index'
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:469:in `_run__375825897__process_action__876887233__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.8) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.8) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.8) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.8) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.8) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.8) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.8) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.8) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.8) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.8) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:600:in `call'
railties (3.2.8) lib/rails/engine.rb:479:in `call'
railties (3.2.8) lib/rails/railtie/configurable.rb:30:in `method_missing'
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'
rack-pjax (0.6.0) lib/rack/pjax.rb:12:in `call'
warden (1.1.1) lib/warden/manager.rb:35:in `block in call'
warden (1.1.1) lib/warden/manager.rb:34:in `catch'
warden (1.1.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/head.rb:14:in `call'
remotipart (1.0.2) lib/remotipart/middleware.rb:30:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/cookies.rb:339:in `call'
activerecord (3.2.8) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `_run__979894838__call__1042350755__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.8) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.8) lib/rails/engine.rb:479:in `call'
railties (3.2.8) lib/rails/application.rb:223:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.8) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
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'
gems used
$ bundle show
Gems included by the bundle:
* actionmailer (3.2.8)
* actionpack (3.2.8)
* activemodel (3.2.8)
* activerecord (3.2.8)
* activeresource (3.2.8)
* activesupport (3.2.8)
* arel (3.0.2)
* bcrypt-ruby (3.0.1)
* bootstrap-sass (2.1.0.1)
* builder (3.0.2)
* bundler (1.1.4)
* carrierwave (0.7.0)
* coffee-rails (3.2.2)
* coffee-script (2.2.0)
* coffee-script-source (1.3.3)
* devise (2.0.4)
* erubis (2.7.0)
* execjs (1.4.0)
* font-awesome-sass-rails (2.0.0.0)
* haml (3.1.7)
* hike (1.2.1)
* i18n (0.6.1)
* journey (1.0.4)
* jquery-rails (2.1.2)
* jquery-ui-rails (2.0.2)
* json (1.7.5)
* kaminari (0.14.1)
* mail (2.4.4)
* mime-types (1.19)
* multi_json (1.3.6)
* mysql (2.8.1)
* nested_form (0.2.3)
* nokogiri (1.5.5)
* orm_adapter (0.0.7)
* polyglot (0.3.3)
* rack (1.4.1)
* rack-cache (1.2)
* rack-pjax (0.6.0)
* rack-ssl (1.3.2)
* rack-test (0.6.1)
* rails (3.2.8)
* rails_admin (0.1.2)
* railties (3.2.8)
* rake (0.9.2.2)
* rdoc (3.12)
* remotipart (1.0.2)
* sass (3.2.1)
* sass-rails (3.2.5)
* sprockets (2.1.3)
* sqlite3 (1.3.6)
* thor (0.16.0)
* tilt (1.3.3)
* treetop (1.4.10)
* twitter-bootstrap-rails (2.0.7 ad1b849)
* tzinfo (0.3.33)
* uglifier (1.3.0)
* warden (1.1.1)
i solved the problem, by using the msql2 gem instead of the mysql gem:
"Notice that I am using the mysql2 adapter instead of mysql. At this point (Feb 2011) the mysql gem is NOT encoding aware. Replace mysql with mysql2 in your Gemfile and run bundle."[see rails-utf-8-and-heroku]
I have a REST API that I am trying to access using Rails 3.0.1 that returns:
<Sessions>
<Session>
<Title>This is a sample title</Title>
...Misc
</Session>
<Session>
<Title>Another Title</Title>
...Misc
</Session>
</Sessions>
I have set up my session.rb class defined:
class Session < ActiveResource::Base
self.site = "http://example.com/rest"
end
The url that will return the XML is http://example.com/rest/sessions.
I then have a controller that is defined as this:
class HomeController < ApplicationController
def index
Session.all
end
end
and my view, index.html.erb, is defined:
<h1>List Sessions</h1>
<% #sessions.each do |session| %>
<div><%= session.title %></div>
<% end %>
When I try to view this page, I get the following error:
NoMethodError in HomeController#index
undefined method `collect!' for #<Hash:0x00000105178af8>
What could be causing this issue? I can access the url just fine (even using http://example.com/rest/sessions.xml). Is there a way to debug ActiveResource to see what is happening inside?
EDIT
Here is the stack trace:
activeresource (3.0.1) lib/active_resource/base.rb:885:in `instantiate_collection'
activeresource (3.0.1) lib/active_resource/base.rb:857:in `find_every'
activeresource (3.0.1) lib/active_resource/base.rb:777:in `find'
activeresource (3.0.1) lib/active_resource/base.rb:803:in `all'
app/controllers/home_controller.rb:4:in `index'
actionpack (3.0.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.1) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.1) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.1) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.1) lib/active_support/callbacks.rb:435:in `_run__140584718597918073__process_action__4423897468290757938__callbacks'
activesupport (3.0.1) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.1) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.1) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.1) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.1) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.1) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.1) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.1) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.1) lib/abstract_controller/rendering.rb:40:in `process'
actionpack (3.0.1) lib/action_controller/metal.rb:133:in `dispatch'
actionpack (3.0.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.1) lib/action_controller/metal.rb:173:in `block in action'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:68:in `optimized_each'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:492:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.1) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/cookies.rb:287:in `call'
activerecord (3.0.1) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.1) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.1) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.1) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.1) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.1) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.1) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/show_exceptions.rb:46:in `call'
railties (3.0.1) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.1) lib/rails/application.rb:168:in `call'
railties (3.0.1) lib/rails/application.rb:77:in `method_missing'
railties (3.0.1) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.1) lib/rack/content_length.rb:13:in `call'
rack (1.2.1) lib/rack/handler/webrick.rb:52:in `service'
/Users/swright/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/swright/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/swright/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Simple answer, if you try to session in your views it will access the Rails Session object, you have a naming problem on your hands.
Thats why the Hash error is coming, it tries to access the session Hash.
Try something like
<h1>List Sessions</h1>
<% #sessions.each do |s| %>
<div><%= s.title %></div>
<% end %>
And by the way, you might change your controller to:
class HomeController < ApplicationController
def index
#sessions = Session.all
end
end
For me the problem was the type was not defined in the xml tag
xml.instruct!
xml.posts("type"=>"array") do
#posts.each do |p|
xml.post do
xml.id("type"=>"integer") do
p.id
end
xml.title p.title
xml.content p.content
end
end
end
vs
xml.instruct!
xml.posts do
#posts.each do |p|
xml.post do
xml.id p.id
xml.title p.title
xml.content p.content
end
end
end
Hope this helps you
I had this problem and like Joel above, it was because the type wasn't defined. I found a solution here but briefly if you don't have any control over the XML you can define a custom format, and tell your ActiveResource class to use it:
class TaxAlert < ActiveResource::Base
protected
class CustomFormat
include ActiveResource::Formats::XmlFormat
def decode(xml)
ActiveResource::Formats::XmlFormat.decode(xml)['alert']
end
end
self.format = CustomFormat.new
end