Question

I'm new to configuring Rails applications in production mode. My Rails application is working correctly, but when I try to run it in production mode it crashes at startup:

 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

here everything is fine, and:

RAILS_ENV=production rails c
/Users/dawid/.rvm/gems/ruby-2.0.0-p195@rails-4.0/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,

I'm just wondering why it works in development mode and not in production mode? What can cause that error?

EDIT:

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
Was it helpful?

Solution

Try this format instead:

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

I think it looks prettier, and is more logical.

Also .exists? looks a little better than your code.

OTHER TIPS

The Rails documentation shows how to use the :status option for render:

2.2.11.4 The :status Option

Rails will automatically generate a response with the correct HTTP status code (in most cases, this is 200 OK). You can use the :status option to change this:

render status: 500 
render status: :forbidden
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top