dimanche 12 juillet 2015

How to create helper method HAML

I inherited a project that uses Ruby on Rails and HAML and I have never seen HAML before so I'm kind of confused. This project is using devise to handle users and devise send flash events or something to notify when a user has logged in or user has failed to log in and other events like that. My problem is that the flash notifications are hard coded to be certain types and I want to tie them to bootstrap alerts with some customization. I know that I can edit the text of the devise notifications but I can't change their types. I have a partial file that is included to display the alerts.

- if flash[:error]
  .alert.alert-error
    %button.close{"data-dismiss" => "alert", :type => "button"} ×
    = flash[:error].html_safe
- elsif flash[:alert]
  .alert.alert-error
    %button.close{"data-dismiss" => "alert", :type => "button"} ×
    = flash[:alert]
- elsif flash[:notice]
  .alert.alert-warning
    %button.close{"data-dismiss" => "alert", :type => "button"} ×
    = flash[:notice]
- elsif flash[:success]
  .alert.alert-success
    %button.close{"data-dismiss" => "alert", :type => "button"} ×
    = flash[:success]

What I would like to do is prefix the devise strings with the alert type that I want them to be.

Take this

Successful log in!

And turn it into this

alert-info|Successful log in!

Then parse the alter type and alter the string. I have no idea if this is possible with a helper method or not.

Aucun commentaire:

Enregistrer un commentaire