LoginSignup
0
0

More than 1 year has passed since last update.

【Rails】dynamic constant assignmentの対処法【Ruby】

Posted at

症状

railsで以下エラーが発生しました。
翻訳すると、「動的定数の割り当て」でした。

error
SyntaxError (C:/app/controllers/api/v1/users_controller.rb:21: dynamic constant assignment
          YOUR_DOMAIN = 'http://localhost:3000'
          ^~~~~~~~~~~
users_controller.rb
def update
user = User.find_by(id: params[:userId])

DOMAIN = 'http://localhost:3000'

if(user.save!(user_params)
  redirect_to DOMAIN + '?success=true',
else
  redirect_to DOMAIN + '?canceled=true',
end

end

解決方法

ApplicationControllerに移動して、解決しました。
定数をアクション内で書いたから怒られていたようです。

application_controller.rb
DOMAIN = 'http://localhost:3000'

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0