問題:我正在嘗試創建一個自定義操作,允許教師通過「批准」操作批准學生。批准操作獲取相應的行並將狀態從「掛起」更改爲「活動」並保存該記錄。目前,當我點擊鏈接,更好的錯誤給了我2Devise/Rails - 未定義的方法`許可'
「爲未定義的方法'許可證」‘’:字符串」
它提到一些關於
設計:: ParameterSanitizer#許可證
請記住,我對Devise很新,很難過!
控制器
class Teachers::RegistrationsController < Devise::RegistrationsController
# APPROVE
def approve
@ts = TeacherStudent.find_by(teacher_id: params[:teacher], student_id: params[:student])
@ts.status = "active"
@ts.save
redirect_to teachers_path
end
end
查看
= link_to "Approve", approve_path(teacher: s.teacher_id, student: s.student_id), method: :put
的routes.rb
put 'teachers' => 'teachers#approve', as: :approve
錯誤
Started PUT "/teachers?student=14&teacher=2" for ::1 at 2015-06-21 01:06:33 -0500
Processing by Teachers::RegistrationsController#update as HTML
Parameters: {"authenticity_token"=>"VQ2zVIv5gof1+38xdAA9d/Y+bWmHk4bT1SXHvc+xLr3+qTOm2xSMZUFjDw74umk35P36kgpqx4eMftFGyVThSg==", "student"=>"14", "teacher"=>"2"}
[1m[36mTeacher Load (0.6ms)[0m [1mSELECT "teachers".* FROM "teachers" WHERE "teachers"."id" = $1 ORDER BY "teachers"."id" ASC LIMIT 1[0m [["id", 2]]
[1m[35mTeacher Load (0.3ms)[0m SELECT "teachers".* FROM "teachers" WHERE "teachers"."id" = $1 LIMIT 1 [["id", 2]]
Completed 500 Internal Server Error in 5ms (ActiveRecord: 1.0ms)
NoMethodError - undefined method `permit' for "2":String:
() Users/dannysun/.rvm/gems/ruby-2.2.1/bundler/gems/devise-15b99977a2a3/lib/devise/parameter_sanitizer.rb:66:in `permit'
() Users/dannysun/.rvm/gems/ruby-2.2.1/bundler/gems/devise-15b99977a2a3/lib/devise/parameter_sanitizer.rb:58:in `account_update'
() Users/dannysun/.rvm/gems/ruby-2.2.1/bundler/gems/devise-15b99977a2a3/lib/devise/parameter_sanitizer.rb:77:in `default_sanitize'
() Users/dannysun/.rvm/gems/ruby-2.2.1/bundler/gems/devise-15b99977a2a3/lib/devise/parameter_sanitizer.rb:24:in `sanitize'
() Users/dannysun/.rvm/gems/ruby-2.2.1/bundler/gems/devise-15b99977a2a3/app/controllers/devise/registrations_controller.rb:141:in `account_update_params'
() Users/dannysun/.rvm/gems/ruby-2.2.1/bundler/gems/devise-15b99977a2a3/app/controllers/devise/registrations_controller.rb:48:in `update'
actionpack (4.2.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.1) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.1) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
activesupport (4.2.1) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:776:in `_run_process_action_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.1) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.1) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.1) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.1) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.1) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.1) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.1) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:43:in `serve'
actionpack (4.2.1) lib/action_dispatch/routing/mapper.rb:49:in `serve'
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:819: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 `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:38:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.1) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:649:in `call'
activerecord (4.2.1) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.1) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:776:in `_run_call_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.1.3) lib/web_console/middleware.rb:37:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.1) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.1) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.1) lib/rails/engine.rb:518:in `call'
railties (4.2.1) lib/rails/application.rb:164:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
/Users/dannysun/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/Users/dannysun/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/Users/dannysun/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
我們需要看到您的設計registrations_controller.rb底部添加以下代碼。特別是底部應該有一些強大的參數方法。 – MarsAtomic
嗯,我是在假設上面發佈的是設計註冊控制器,如果是這樣的話,那就是那裏的一切。 –
請發佈完整的錯誤堆棧跟蹤。 – Pavan