会话不在rails中的post方法中工作

时间:2015-08-21 12:17:18

标签: ruby-on-rails session

session [:user_id] = user.id此会话无法正常工作,但其工作在get方法(登录)

  # Working fine here
  # get 'users/login'=>'users#login'
  def login
    session[:user_id] = 1
  end

  # post 'users/auth'=>'users#loginpost'
  def loginpost
      user = User.authenticate(request.POST['name'], request.POST['password'])
    if user
      # But not working here:(
      session[:user_id] = user.id
      redirect_to root_url, :notice => "You are Successfully logged in ^^"
    else
      render html: '<strong>HTML String</strong>'
      #render users_login_url, :notice => "You are entered invalid email or password"
    end
  end

0 个答案:

没有答案