在生产模式下运行Rails应用程序时出错

问题描述 投票:0回答:2

我是新手在生产模式下配置Rails应用程序。 我的Rails应用程序工作正常,但是当我尝试在生产模式下运行它时它在启动时崩溃:

 rails s
=> Booting WEBrick
=> Rails 4.0.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server

这里一切都很好,并且:

RAILS_ENV=production rails c
/Users/dawid/.rvm/gems/[email protected]/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `require': /Users/dawid/workspace/demioorg/Dineria/backend/app/controllers/users/users_controller.rb:6: syntax error, unexpected ':', expecting keyword_end (SyntaxError)
      render_status: 200,

我只是想知道为什么它在开发模式下工作而不是在生产模式下? 什么可能导致错误?

编辑:

class Users::UsersController < Devise::SessionsController
  respond_to :json

  def is_user
    if current_user.present?
      render_status: 200,
        json: {
          success: !User.find_by_name(params[:name]).blank?
        }
    end
  end

end
ruby-on-rails production-environment
2个回答
1
投票

Rails文档显示了如何使用:status选项进行render

2.2.11.4:状态选项

Rails将使用正确的HTTP状态代码自动生成响应(在大多数情况下,这是200 OK)。 您可以使用:status选项更改此设置:

render status: 500 
render status: :forbidden

1
投票

请尝试使用此格式:

render :status => 200, 
       :json   => {success: User.exists?(:name => params[:name])}

我认为它看起来更漂亮,更合乎逻辑。

.exists? 看起来比你的代码好一点。

© www.soinside.com 2019 - 2024. All rights reserved.