Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 未定义的方法“重定向回”或';_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 未定义的方法“重定向回”或';

Ruby on rails 未定义的方法“重定向回”或';,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我一直在关注迈克尔·哈特尔(Michael Hartl)的Rails教程,为那些熟悉我的人提供“第10课:更新、显示和删除用户”(使用LiveLessons视频版本) 我想我可能会提到,我已经将“重定向回”或“重定向回”的定义添加到我的会话助手中,并将Include sessionhelp函数添加到我的应用程序控制器中 我希望我们能解决这个问题,我提供了下面的日志。注意:谁能解决这一问题是天才,因为这似乎是一个尚未解决的谜团 登录时出错: 会话控制器中的NoMethodError#创建 编辑新添

我一直在关注迈克尔·哈特尔(Michael Hartl)的Rails教程,为那些熟悉我的人提供“第10课:更新、显示和删除用户”(使用LiveLessons视频版本)

我想我可能会提到,我已经将“重定向回”或“重定向回”的定义添加到我的会话助手中,并将Include sessionhelp函数添加到我的应用程序控制器中

我希望我们能解决这个问题,我提供了下面的日志。注意:谁能解决这一问题是天才,因为这似乎是一个尚未解决的谜团

登录时出错:

会话控制器中的NoMethodError#创建 编辑新添加//应用程序控制器: 更新:

问题解决了,多亏比灵顿注意到了商店的位置连接+1. 这: 应该是:
您已经在帮助器中定义了
def redirect\u back\u或(默认)
。您不能像现在这样从控制器访问它

尝试将其命名为:
@template.redirect\u back\u或(…)
@view\u contest.redirect\u back\u或(…)
(其中一个应该可以工作-我忘了哪个版本的Rails是哪个版本)


另一个选项是将该方法移动到控制器中。(更好,IMO)

您已经在帮助程序中定义了
def redirect\u back\u或(默认)
。您不能像现在这样从控制器访问它

尝试将其命名为:
@template.redirect\u back\u或(…)
@view\u contest.redirect\u back\u或(…)
(其中一个应该可以工作-我忘了哪个版本的Rails是哪个版本)


另一个选项是将该方法移动到控制器中。(更好,IMO)

您的助手方法应该如下所示

def redirect_back_or(default)
  redirect_to(session[:return_to] || default)
  session.delete(:return_to)
end

不清楚\u return \u to

您的助手方法应该如下所示

def redirect_back_or(default)
  redirect_to(session[:return_to] || default)
  session.delete(:return_to)
end

不清楚\u返回\u至

是否需要重新启动服务器?如果没有,您可以发布您的应用程序控制器吗?我们可以看到您的帮助程序代码吗?当然,我已经添加了会话帮助程序、应用程序控制器和完整跟踪日志。您在哪里定义了该方法?它不在您发布的帮助程序中…定义为:def redirect_back_或(默认)redirect_to(会话[:return_to]| |默认)clear_return_to end//在会话帮助程序的中下部。是否需要重新启动服务器?如果没有,您可以发布您的应用程序控制器吗?我们可以看到您的帮助程序代码吗?当然,我已经添加了会话帮助程序、应用程序控制器和完整跟踪日志。您在哪里定义了该方法?它不在您发布的帮助程序中…定义为:def redirect_back_或(默认)redirect_to(会话[:return_to]| |默认)clear_return_to end//在会话帮助程序的中下部。
pp/controllers/sessions_controller.rb:15:in `create'
actionpack (3.2.11) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.11) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.11) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.11) lib/active_support/callbacks.rb:414:in `_run__1623305808682769517__process_action__2997016911314885603__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.11) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.11) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.11) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.11) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.11) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.11) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.11) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.11) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.11) 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.11) lib/action_dispatch/routing/route_set.rb:601:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.4) lib/rack/etag.rb:23:in `call'
rack (1.4.4) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.4) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.4) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.11) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.11) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `_run__3609576242730521204__call__105225653498443597__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.11) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.11) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.11) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.4) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.4) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.11) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.4) lib/rack/lock.rb:15:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.11) lib/rails/engine.rb:479:in `call'
railties (3.2.11) lib/rails/application.rb:223:in `call'
rack (1.4.4) lib/rack/content_length.rb:14:in `call'
railties (3.2.11) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.4) lib/rack/handler/webrick.rb:59:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
class ApplicationController < ActionController::Base
  protect_from_forgery
  include SessionsHelper
end
module SessionsHelper

  def sign_in(user)
    cookies.permanent.signed[:remember_token] = [user.id, user.salt]
    current_user = user
  end

  def current_user=(user)
    @current_user = user
  end

  def current_user
     @current_user ||= user_from_remember_token
   end

   def signed_in?
     !current_user.nil? 
   end

   def sign_out
     cookies.delete(:remember_token)
     self.current_user = nil
   end 


   def current_user?(user)
     user == current_user
   end

   def deny_access
     store_location
     redirect_to signin_path, :notice => "Please sign in to access this page." 
   end

   def store_location
     session[:return_to] = request.fullpath

     def redirect_back_or(default)
         redirect_to(session[:return_to] || default)
         clear_return_to
   end

   def clear_return_to
     session[:return_to] = nil
   end

  end

   private

   def user_from_remember_token
     User.authenticate_with_salt(*remember_token)
   end

   def remember_token
     cookies.signed[:remember_token] || [nil, nil]
   end



end
    module SessionsHelper

  def sign_in(user)
    cookies.permanent.signed[:remember_token] = [user.id, user.salt]
    current_user = user
  end

  def current_user=(user)
    @current_user = user
  end

  def current_user
     @current_user ||= user_from_remember_token
   end

   def signed_in?
     !current_user.nil? 
   end

   def sign_out
     cookies.delete(:remember_token)
     self.current_user = nil
   end 


   def current_user?(user)
     user == current_user
   end

   def deny_access
     store_location
     redirect_to signin_path, :notice => "Please sign in to access this page." 
   end

   def store_location
     session[:return_to] = request.fullpath

     def redirect_back_or(default)
         redirect_to(session[:return_to] || default)
         clear_return_to
   end

   def clear_return_to
     session[:return_to] = nil
   end

  end

   private

   def user_from_remember_token
     User.authenticate_with_salt(*remember_token)
   end

   def remember_token
     cookies.signed[:remember_token] || [nil, nil]
   end



end
module SessionsHelper

  def sign_in(user)
    cookies.permanent.signed[:remember_token] = [user.id, user.salt]
    current_user = user
  end

  def current_user=(user)
    @current_user = user
  end

  def current_user
     @current_user ||= user_from_remember_token
   end

   def signed_in?
     !current_user.nil? 
   end

   def sign_out
     cookies.delete(:remember_token)
     self.current_user = nil
   end 


   def current_user?(user)
     user == current_user
   end

   def deny_access
     store_location
     redirect_to signin_path, :notice => "Please sign in to access this page." 
   end

  def store_location
     session[:return_to] = request.fullpath
end 

     def redirect_back_or(default)
         redirect_to(session[:return_to] || default)
         clear_return_to
   end

   def clear_return_to
     session[:return_to] = nil
   end


   private

   def user_from_remember_token
     User.authenticate_with_salt(*remember_token)
   end

   def remember_token
     cookies.signed[:remember_token] || [nil, nil]
   end



end
def redirect_back_or(default)
  redirect_to(session[:return_to] || default)
  session.delete(:return_to)
end