Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a flash notice to a link?

Is it possible to add a flash notice when someone clicks a static link?

<%= link_to "show clip", sign_up_page_path, notice: "You must sign up or sign in to view clips." %>

The fact is, it's not an authentication issue because the content is static, I'd just like to manually link to the sign-up page and throw a notice stating that the user must "sign up or sign in to view clips."

like image 672
user3399101 Avatar asked Mar 04 '26 05:03

user3399101


1 Answers

Flash:

If you look at rail guides, it says

The flash is a special part of the session which is cleared with each request. This means that values stored there will only be available in the next request, which is useful for passing error messages etc.

link_to:

If you look at your link_to syntax:

link_to(body, url, html_options = {})
# url is a String; you can use URL helpers like
# posts_path

Is it possible to add a flash notice when someone clicks a static link

The answer would be no because if you look at link_to syntax then it just doesn't allow you to set a flash message

Fix:

As @Max Williams pointed out you can use browsers dialog box to alert user to sign up and then redirect him/her to your sign up page. You can also use bootstraps modal to display your message but personally i think bootstrap popover would be much better than a modal or you can simply display a tooltip asking user to sign up or sign in

like image 164
Mandeep Avatar answered Mar 06 '26 20:03

Mandeep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!