I am using Devise for authentication in my website.
I want the user be able to post in the text area if he/she is signed in, if not he’ll type what he wants to post in the textarea and when he click on post it pops up a sign-in dialog where user sign-in/sign-up and then it automatically post his comment in the text area to the website.
I’m not sure if I’m using the right logic, but I have the post button to post the comment if user signed-in, otherwise do nothing and javascript opens up the login-dialog. The login/sing-up works but I figure out how to post the message automatically after that.
This is my code for the button:
<% if user_signed_in? %>
<%= f.submit :value => t(:submit_comment_text), :class => "submit-button" %>
<% else %>
<input class="submit-button" id="comment_submit_nlogged" value="Post!"/>
<% end %>
The first part works fine, but the second part the dialog opens up and the user sign in, but it refreshes the page and I loose whatever user typed in the text-area.
I tried to get the content of the text-area through the params variable, but when devise gets called the params for text area goes away and they get replaced by devise params.
Any idea how I can get this working?
You can save the text area in a session variable like
session[:text_area] = params[:text_area]repopulate the
@commentobject in the controller method usingsession[:text_area]and remove it.You can read about Rails Sessions here
There can also use cookies(if the textarea content is small) or HTML localStorage( if your browser supports it)