devise icon indicating copy to clipboard operation
devise copied to clipboard

Devise's generated model code contains syntax errors

Open ghost opened this issue 1 year ago • 0 comments

Environment

  • Ruby ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin22]
  • Rails Rails 7.2.2
  • Devise 4.9.4

Current behavior

Created a new Rails app for the first time in a long time. Added Devise, generated models and ran migrations successfully.

Expected behavior

A bootable app.

Actual behavior

The call to the devise method that was automatically inserted into my user.rb file throws syntax errors:

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable :registerable
         :recoverable, :rememberable, :validatable

  enum :role, [:user, :admin, :superadmin]

  after_initialize :set_default_role, if: :new_record?

  # set default role to user  if not set
  def set_default_role
    self.role ||= :user
  end
end
% rails server
=> Booting Puma
=> Rails 7.2.2 application starting in development 
=> Run `bin/rails server --help` for more startup options
Exiting
/Users/myuser/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `require': --> /Users/myuser/dev/myorg/alfalfa/app/models/user.rb
expected a newline or semicolon after the statementcannot parse the expression
   1  class User < ApplicationRecord
>  4    devise :database_authenticatable :registerable
>  5           :recoverable, :rememberable, :validatable
>  7    enum :role, [:user, :admin, :superadmin]
  15  end

/Users/myuser/dev/myorg/alfalfa/app/models/user.rb:4: syntax error, unexpected ':', expecting `end' or dummy end (SyntaxError)
...ise :database_authenticatable :registerable
...                              ^
/Users/myuser/dev/myorg/alfalfa/app/models/user.rb:5: syntax error, unexpected ',', expecting `end' or dummy end
         :recoverable, :rememberable, :validatable
                     ^

Did I get some incompatible version mismatches somehow?

ghost avatar Jan 13 '25 01:01 ghost