2013-11-26 129 views
0

我是新來的在生產模式下配置Rails應用程序。我的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 
+0

你可以顯示你的users_controller嗎? – dax

+0

我用users_controller編輯了我的問題。但我不知道爲什麼它只能在開發模式下正常工作 – Dawid

+0

如果你嘗試: render:json => {success:...},:status => 200 ? – Niall

回答

1

試試這個格式來代替:

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

我認爲它看起來更漂亮,更符合邏輯。

另外.exists?看起來比你的代碼好一點。

+0

謝謝,它的工作原理。我沒有意識到這一點。 – Dawid

+0

也存在?看起來好多了 – Dawid

1

Rails documentation展示瞭如何使用render:status選項:

2.2.11.4的:狀態選項

Rails會自動生成與響應正確的HTTP狀態碼(在大多數情況下,這是200 OK)。您可以使用:狀態選項更改此:

render status: 500 
render status: :forbidden 
相關問題