Recently got a new job as a Rails developer, having never previously used the language and it’s quite a leap.
I’m working on a locked screen effect for the website, where a link can be clicked which blanks the webpage and requires the user to enter their password again in order to remove the overlay. The overlay is a jQuery modal as follows:
$().ready( function() {
$('.blackoutwindow').jqm({
modal: true,
trigger: '.blackout',
overlay: 100
});
if (boset) {
$('.blackoutwindow').jqmShow();
}
});
When the link with id “blackout” is clicked the window appears. The JS variable boset is set in my view from a Rails session var which determines if the user has the screen blanked (so that the blanking persists on refresh, etc) <%= javascript_tag "var boset = #{session[:blanked]} "%>
Inside the modal div is my Rails password form:
<%= form_tag passcheck_path, :id => "passcheck", :remote => true do -%>
<%= hidden_field_tag :email, current_user.email %>
<ul>
<li><%= password_field_tag 'password', nil, { :size => 30, :maxlength => 80, :class => :required } %></li>
<li><%= submit_tag 'Submit' %></li>
<li><span class="ajaxmessage"> </span></li>
</ul>
<% end -%>
Which (by means which I don’t really understand) sends the password to an action in my sessions_controller.rb called passcheck, in a kind of AJAX style, which authenticates the password.
Now that I’ve explained where I am currently, how do I now close the jQuery modal if the password is correct, update the span .ajaxmessage if the password isn’t correct, and also, set the session variable when someone originally clicks on the “blank screen” link?
Hope I was clear enough, any questions, fire away..
Got it working, mostly, except this remaining problem.
In my controller I put:
Then I created a passcheck.js.erb which is the javascript that I want executed when the form is submitted: