I would just add a query string parameter to whatever url you are redirecting to after signup. For example:
def after_sign_up_path_for(resource)
root_path(show_welcome_popup: true)
end
See How To: Redirect to a specific page on successful sign up (registration)
Then you can just check:
<%= if params[:show_welcome_popup] %>
# ...
<% end %>
After you have displayed the popup use history.replaceState
to modify the browser history:
// path/to/some/file.js
history.replaceState(null, window.title, window.location.pathname)
This will prevent the popup from reappearing if the user hits the back button which is a nice touch.
I solved with the following code line.
<% if current_user.sign_in_count == 1 %>
<div class="modal fade in" id="myModal0" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content" style="width: 90%" >
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<h3 style="color: black; position: center">¡Welcome! <%=current_user.name%>.</h3>
<iframe src="/uploads/pdfs/5.pdf" width="700px" height="650px"></iframe>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<%=current_user.increment!(:sign_in_count) %>
<%end %>
what the next line does <%=current_user.increment!(:sign_in_count) %>
is to officially increase an attribute, in this case :sign_in_count
it is the attribute to increase.
Cheers.
I am trying to put a modal for new users, that says “Welcome” (or other message), I am using “sign_in_count” to record the number of logins.
At the moment I have something like this:
<% if current_user.sign_in_count == 1 %>
<div class="modal fade in" id="myModal0" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content" style="width: 90%" >
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<h3 style="color: black; position: center">¡Welcome! <%=current_user.name%>.</h3>
<iframe src="/uploads/pdfs/5.pdf" width="700px" height="650px"></iframe>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<%end %>
obviously, if the user enters for the first time, sign_in_count
will always be equal to 1 and the modal will appear every time the user reloads the page, unless the user disconnects and re-enters (that is not the idea); and if sign_in_count+=1
there is no increase as such. Can there be a way where sign_in_count is 2
at the first login? The modal must appear when the user is new; or any solution you can offer? I really appreciate the help.
Cheers and thanks!
Thanks for you help, but consulting more deeply on the internet, I found what I needed