app/controllers/application_controller.rb
Use find_by
instead of dynamic find_by_id
. (https://github.com/bbatsov/rails-style-guide#find_by) Open
Open
User.find_by_id(session[:user_need_verify]['id']) if session[:user_need_verify].present?
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks dynamic find_by_*
methods.
Use find_by
instead of dynamic method.
See. https://github.com/bbatsov/rails-style-guide#find_by
Example:
# bad
User.find_by_name(name)
# bad
User.find_by_name_and_email(name)
# bad
User.find_by_email!(name)
# good
User.find_by(name: name)
# good
User.find_by(name: name, email: email)
# good
User.find_by!(email: email)
Use a guard clause instead of wrapping the code inside a conditional expression. (https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals) Open
Open
unless current_user.identified?(cookies[:identify_token])
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Redundant return
detected. (https://github.com/bbatsov/ruby-style-guide#no-explicit-return) Open
Open
return
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for redundant return
expressions.
Example:
def test
return something
end
def test
one
two
three
return something
end
It should be extended to handle methods whose body is if/else or a case expression with a default branch.