Friday, 15 June 2012

ruby on rails - User model: username format method -



ruby on rails - User model: username format method -

ok, in user model have created get_username in effort format username.

the thought able use

theuser.get_username

and correctly format username based on user level (admin). test created this:

def get_username fname = '<span style="color:red">john</span>' fname end

however, displayed value literally code showing..

how able plug username in display correctly

you can utilize html_safe.

def get_username fname = '<span style="color:red">john</span>' fname.html_safe end

to user_name use:

def get_username fname = "<span style='color:red'>#{user_name}</span>" fname.html_safe end

note bad code, not abusing seperation of responsibilty of mvc may introduce security vulernabilities.

code should in view or helper.

ruby-on-rails ruby format username

No comments:

Post a Comment