" redirect_to的" - 在控制台我得到一个消息,页面被重定向但在浏览器上页面没有显示

时间:2015-05-21 07:42:07

标签: ruby-on-rails ruby

如方法控制台所示,create方法正在执行,但重定向无法在浏览器上呈现。 控制器

def create
  #try to authenticate the user - if they authenticate successfully, an instance of the User model is returned
  @user = User.authenticate(params[:email], params[:password])
  #if an instance is returned and @user is not nil...
  if @user
    #let the user know they've been logged in with a flash message
    flash.now[:notice] = "You've been logged in."
    #THIS IS THE MOST IMPORTANT PART. Actually log the user in by storing their ID in the session hash with the [:user_id] key!
    session[:user_id] = @user.id
    #then redirect them to the homepage
    redirect_to "/"
    return
  else
    #whoops, either the user wasn't in the database or their password is incorrect, so let them know, then redirect them back to the log in page
    flash.now[:alert] = "There was a problem logging you in."
    redirect_to "/log-in"
    return
  end
end

控制台

Started POST "/log-in?              create=%7B%22method%22:%22PUT%22,%22responseType%22:%22json%22%7D" for 127.0.0.1         at 2015-05-21 12:51:36 +0530

Processing by SessionsController#create as HTML 
Parameters: {"email"=>"harsh@gmail.com", "password"=>"[FILTERED]", "create"=>"{\"method\":\"PUT\",\"responseType\":\"json\"}", "session {"email"=>"harsh@gmail.com", "password"=>"[FILTERED]"}}

User Load (22.0ms)  SELECT  "users".* FROM "users"  WHERE "users"."email" = 'harsh@gmail.com'  ORDER BY "users"."id" ASC LIMIT 1
this is user entered passwordharsh
this is encript hash passwors$2a$10$kPfxXAMxcWHhJjcO9ubXv.Q2xbCMPA6K2epe/dGX5EDAIcbmnvJDi
Redirected to http://localhost:3000/
Completed 302 Found in 307ms (ActiveRecord: 23.0ms)


Started GET "/" for 127.0.0.1 at 2015-05-21 12:51:37 +0530 
Processing by UsersController#index as HTML   
Rendered users/index.html.erb within layouts/application (0.0ms) 
Completed 200 OK in 349ms (Views:324.0ms | ActiveRecord: 0.0ms)

我搜索了类似的问题,并尝试了所有的答案,但它仍然没有在浏览器上呈现。 如果您知道答案,请提供帮助

由于

1 个答案:

答案 0 :(得分:0)

从最后一行删除return。 Rails在被调用的动作的最后一行上查找重定向/呈现。如果可以,请告诉我。

希望这有帮助!