1
私のRails 3アプリケーションで、いくつかの特定のアクションでCanCanを動作させようとしています。私はAbility.rb
クラスで自分の役割を定義しましたが、何かが生産と開発の両方でエラーを引き起こしています。私は、ユーザーの役割に応じてリンクを表示/非表示するcan?
を呼び出すときに具体的に、私は次を得る:Rails 3 appでCanCanエラー - ArgumentError引数が間違っています(2の場合1)
ArgumentError in Higher_eds#show
Showing /Users/me/Desktop/myapp/app/views/higher_eds/_logged_in.html.erb where line #62 raised:
wrong number of arguments (2 for 1)
誰も私には何が起こっているかを把握助けることができますか?
私は私の/higher_eds/_logged_in.html.erb
ビューに次のように呼び出すことにより、エラーを取得しています:
def highered_students
@highered = HigherEd.find(params[:id])
@profiles = Profile.where %[higher_ed = ? AND EXTRACT(year FROM college_grad_year) > EXTRACT(year FROM current_date)], @highered.name
respond_to do |format|
format.js { render :layout => nil }
end
end
マイAbility.rb
:
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new #guest user
if user.role? :highered_admin
can :highered_students, HigherEd
end
if user.role? :admin
can :manage, :all
end
end
end
higher_eds_controller.rb
で私highered_students
アクションで
<% if can? :highered_students, @highered %>
<li><%= link_to "Students", highered_students_higher_ed_path, :class=> 'inactive', :remote => true %></li>
<% end %>
を私の完全なトレース:
activerecord (3.0.5) lib/active_record/attribute_methods/query.rb:34:in `attribute?'
activemodel (3.0.5) lib/active_model/attribute_methods.rb:362:in `method_missing'
activerecord (3.0.5) lib/active_record/attribute_methods.rb:46:in `method_missing'
app/models/ability.rb:6:in `initialize'
cancan (1.6.7) lib/cancan/controller_additions.rb:349:in `new'
cancan (1.6.7) lib/cancan/controller_additions.rb:349:in `current_ability'
cancan (1.6.7) lib/cancan/controller_additions.rb:372:in `can?'
actionpack (3.0.5) lib/abstract_controller/helpers.rb:55:in `can?'
app/views/higher_eds/_logged_in.html.erb:62:in `block in _app_views_higher_eds__logged_in_html_erb__1309160371424325548_70132578271280__1361790216911758374'
actionpack (3.0.5) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
actionpack (3.0.5) lib/action_view/helpers/capture_helper.rb:172:in `with_output_buffer'
actionpack (3.0.5) lib/action_view/helpers/capture_helper.rb:40:in `capture'
actionpack (3.0.5) lib/action_view/helpers/tag_helper.rb:77:in `content_tag'
actionpack (3.0.5) lib/action_view/helpers/record_tag_helper.rb:59:in `content_tag_for'
actionpack (3.0.5) lib/action_view/helpers/record_tag_helper.rb:21:in `div_for'
app/views/higher_eds/_logged_in.html.erb:1:in `_app_views_higher_eds__logged_in_html_erb__1309160371424325548_70132578271280__1361790216911758374'
actionpack (3.0.5) lib/action_view/template.rb:135:in `block in render'
activesupport (3.0.5) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.5) lib/action_view/template.rb:127:in `render'
actionpack (3.0.5) lib/action_view/render/partials.rb:333:in `render_partial'
actionpack (3.0.5) lib/action_view/render/partials.rb:262:in `block in render'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.5) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.5) lib/action_view/render/partials.rb:260:in `render'
actionpack (3.0.5) lib/action_view/render/partials.rb:378:in `_render_partial'
actionpack (3.0.5) lib/action_view/render/rendering.rb:22:in `render'
app/views/higher_eds/show.html.erb:2:in `_app_views_higher_eds_show_html_erb__2358915598045819601_70132577771800__3922384299851769153'
actionpack (3.0.5) lib/action_view/template.rb:135:in `block in render'
activesupport (3.0.5) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.5) lib/action_view/template.rb:127:in `render'
actionpack (3.0.5) lib/action_view/render/rendering.rb:59:in `block in _render_template'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.5) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.5) lib/action_view/render/rendering.rb:56:in `_render_template'
actionpack (3.0.5) lib/action_view/render/rendering.rb:26:in `render'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:115:in `_render_template'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:109:in `render_to_body'
actionpack (3.0.5) lib/action_controller/metal/renderers.rb:47:in `render_to_body'
actionpack (3.0.5) lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:102:in `render_to_string'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:93:in `render'
actionpack (3.0.5) lib/action_controller/metal/rendering.rb:17:in `render'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.0.5) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
activesupport (3.0.5) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.0.5) lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:39:in actionpack `render'
app/controllers/higher_eds_controller.rb:42:in `show'
actionpack (3.0.5) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.5) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.5) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.5) lib/active_support/callbacks.rb:440:in `_run__4596096755335087880__process_action__1011169593507530898__callbacks'
activesupport (3.0.5) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.5) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.5) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.5) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.5) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.5) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.5) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.5) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.5) 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:145: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.5) lib/action_dispatch/routing/route_set.rb:492:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.5) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.5) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.5) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.5) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.5) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.5) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.5) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.5) lib/rack/sendfile.rb:106:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.5) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.5) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.5) lib/rack/lock.rb:13:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.5) lib/rack/lock.rb:13:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.5) lib/rails/application.rb:168:in `call'
railties (3.0.5) lib/rails/application.rb:77:in `method_missing'
railties (3.0.5) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.5) lib/rack/content_length.rb:13:in `call'
rack (1.2.5) lib/rack/handler/webrick.rb:52:in `service'
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'