Persistently bugging someone about updating their profile, the 'Rails way'?
In my Rails application, I wanted a user to be persistently shown a
warning notice to update their profile, until they do it. Specifically I
want them to fill in their name ASAP, but I don't want them to do that
during signup. So I wrote the following in a partial that is loaded in my
application layout:
<% if user_signed_in? && current_user.profile.name == nil %>
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert"
aria-hidden="true">×</button>
Please fill in your Profile as soon as possible. This information is
important for you to use the application properly.
<%= link_to "Do it now", edit_profile_path(current_user) %>
</div>
<% end %>
However I feel like this is a really clunky way to do it. Firstly this
means that every time a signed in user accesses a page, there's a database
check for their profile as well. Secondly it's logic in the view.
So my question is, what would be a more 'Rails way' to do this? Somehow
move the logic into the application controller? Load the result of the
logic into a session variable or something so that the database doesn't
need to be checked every page load?
No comments:
Post a Comment