I’d like to present a first-time user with a welcome message that appears until the user ‘closes’ the message one time. (via jQuery’s hide method).
How can this best be accomplished? I’m using Rails 3.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In order for the welcome message to persist between actions, you’d need to save something in the database to record whether or not the user has closed the message. You could do this by adding a column to the User model:
Include a conditional statement in your layout/view to check whether it should display the welcome message:
Then when the user clicks the ‘hide’ button, you could have jquery call a controller action asynchronously:
Then create a controller action that hides the message permanently
You’d need to create a route for this action too:
Now that I’ve typed this out it seems a bit long-winded, perhaps someone can come up with something much neater. If you were going to have many different messages, your User model could get very messy – I’d probably start a new MessageAction model the belongs_to User, with a boolean field for each message type.