Rails 4应用程序的动态方面无法在生产中使用

时间:2014-08-08 23:06:37

标签: mysql ruby-on-rails ruby-on-rails-4

我刚刚将第一个rails 4应用程序部署到VPS,现在我无法写入生产数据库。所有部署都很好(迁移等),我可以使用续集专业版登录mysql数据库,但是当我尝试使用应用程序的新用户表单创建用户而不是通知时,看到它就在那里了,谢谢你注册' (正如它在开发中一样)它要求我登录继续。没有在数据库中创建记录。

我可以在日志中看到它是绑定显示而不是用户id到:id参数,因此重定向到登录而不是创建会话。为什么会这样?

这是应用程序日志

I, [2014-08-09T00:33:45.753714 #31030]  INFO -- : Started GET "/login" for xx.xxx.xxx.xx at 2014-08-09 00:33:45 +0200
I, [2014-08-09T00:33:45.755372 #31030]  INFO -- : Processing by SessionsController#new as HTML
I, [2014-08-09T00:33:45.757942 #31030]  INFO -- :   Rendered sessions/new.html.erb within layouts/application (1.1ms)
I, [2014-08-09T00:33:45.758940 #31030]  INFO -- : Completed 200 OK in 3ms (Views: 2.5ms | ActiveRecord: 0.0ms)
I, [2014-08-09T00:33:52.048559 #31030]  INFO -- : Started POST "/sessions" for xx.xxx.xxx.xx at 2014-08-09 00:33:52 +0200
I, [2014-08-09T00:33:52.050765 #31030]  INFO -- : Processing by SessionsController#create as HTML
I, [2014-08-09T00:33:52.050912 #31030]  INFO -- :   Parameters: {"utf8"=>"?^?^?", "authenticity_token"=>"xxxxxxxxxxxxxxxx", "email"=>"xxxx@gmail.com", "password"=>"[FILTERED]", "commit"=>"Log In"}
I, [2014-08-09T00:33:52.056027 #31030]  INFO -- :   Rendered sessions/new.html.erb within layouts/application (1.4ms)
I, [2014-08-09T00:33:52.057333 #31030]  INFO -- : Completed 200 OK in 6ms (Views: 3.1ms | ActiveRecord: 0.7ms)
I, [2014-08-09T00:34:16.625949 #31030]  INFO -- : Started GET "/users/show" for 92.225.136.50 at 2014-08-09 00:34:16 +0200
I, [2014-08-09T00:34:16.628217 #31030]  INFO -- : Processing by UsersController#show as HTML
I, [2014-08-09T00:34:16.628359 #31030]  INFO -- :   Parameters: {"id"=>"show"}
I, [2014-08-09T00:34:16.630009 #31030]  INFO -- : Redirected to http://xx.xxx.xxx.xx/
I, [2014-08-09T00:34:16.630207 #31030]  INFO -- : Filter chain halted as :authorize rendered or redirected
I, [2014-08-09T00:34:16.630443 #31030]  INFO -- : Completed 302 Found in 2ms (ActiveRecord: 0.0ms)

编辑1:这是我的会话控制器:

class SessionsController < ApplicationController
  def new
  end

  def create
    user = User.find_by_email(params[:email])
    if user && user.authenticate(params[:password])
      session[:user_id] = user.id
      redirect_to users_path, notice: "Logged In!"
    else
      flash.now[:error] = "Email or password is invalid. Please try again."
      render "new"
    end
  end

  def destroy
    session[:user_id] = nil
    redirect_to root_url, notice: "Logged Out!"
  end
end

这是我的用户控制器:

class UsersController < ApplicationController
  before_action :authorize, except: [:new]

  def new
    @user = User.new
  end

  def edit
    @user = User.find(params[:id])
  end

  def show
    @user = User.find(params[:id])
    @microposts = @user.microposts.paginate(page: params[:page])
   end

   def update
     respond_to do |format|
      @user = User.find(params[:id])
      if @user.update(user_params)
        format.html { redirect_to @user, notice: 'User was successfully updated.' }
        format.json { render :show, status: :ok, location: @user }
      else
        format.html { render :edit }
        format.json { render json: @user.errors, status: :unprocessable_entity }
      end
    end
  end

  def destroy
    @user = User.find(params[:id])
    if @user.present?
    @user.destroy
    end
    redirect_to users_path, notice: "User successfully deleted."
   end

  def create
    @user = User.new(params[:user].permit(:name, :surname, :title, :telefon, :email, :password, :password_confirmation, :salt, :encrypted_password))
    if @user.save
      session[:user_id] = @user.id
      redirect_to root_url, notice: "Vielen Dank für Ihre Anmeldung"
    else
      render "new"
    end
  end

  def index
    @users = User.all
  end

  private
  def user_params
      params.require(:user).permit(:name, :surname, :title, :telefon, :email, :password, :password_confirmation, :salt, :encrypted_password)
  end
end

0 个答案:

没有答案