Reputation: 10207
In my Rails 3 application I am using a before_filter
to make sure that the action can only be used by permanent
users, i.e. users that are not guests:
def permanent_user
@user = User.where('guest != ?', true).find(params[:id])
redirect_to(root_path) unless current_user?(@user)
end
The problem is that I frequently get a ActiveRecord::RecordNotFound
error in the first line when the number of total users in the database is very low.
How can my function be improved to either create a @user
object or nil
?
Thanks for any help.
Upvotes: 0
Views: 83
Reputation: 51151
How about this?
def permanent_user
redirect_to root_path if current_user.guest?
@user = current_user
end
Upvotes: 4