#5 Florrick

Summary

This is a Rails library which integrates with Active Records and provides some awesome user-initiated string interpolations for your web apps. For example, have you ever needed to allow users to insert their own variables into e-mail templates or messages?
rails model strings 6:28

Summary

Gemfile  gem 'florrick'
Passing a block into the florrick method.

user.rb
  class User < ActiveRecord::Base
    florrick do
      string :first_name, :last_name
      string(:full_name) { "#{first_name} #{last_name}"}
      string(:age) { Date.today.year - birthday.year - (birthday.to_date.change(year: Date.today.year) > Time.now ? 1 : 0)}
    end
  end

  # {{user.full_name}}
In the Rails console, we saw how the options are passed through Florrick.convert to interpret the strings and replace them with our dynamic content.

console  string = "Happy Birthday {{user.full_name}}."
  string = "Happy Birthday {{user.full_name}}. You are now {{user.age}} years old!"
  Florrick.convert(string, user: user)
there were a term for a passenger in hand and learned really large mall to it at each end the answer for users you and it creates cause medications said well which them a happy birthday the paper for their birthday and hers so you want to create this notification personally said to you that employee your user ooh as having a birthday so from within here you have your hello user but you what this actually say the employee's name or the user's name now the problem with this is while we could create a steam i'll email or and customize awaken there that's a very static way of doing this because the usual i'm not be able to customize us at all so today we're gonna look at how old they can customize us themselves again using string up in a glacier weekend how to create the for red and the text with the information that we were to inject that but to get started the score towards him pile it meant the floor to afford a gym is a great chairman a link to the guitar were positive with the show notes but it's where we can take our tax man use som mustaches here to within our feel no you don't necessarily want to open this up so the clink you put anything in here because they could pose a security rest and so what's brown bottle and don't forget to me sir you will to application to pick up the new gen to the person we we need to do is going to war model for the user and tied for it you and here we get passes are are patchy these are gonna open up to four so let's call stream first name and what's also called the last minute what this will allow us to do those know well as suit has sent the user died first name there we can also destiny use it on les les however if we want to make this a bit simpler for the korean and just welcome to the full name we don't have a full name attribute or or model because we have individual action beach for the first in the last name whoever we do want to make this world it's awkward to just below to call you see the folding we can do this by a guy just putting prince's he's around here are passing and my sessions here and then we can just use e string of polish and here to call the first name and then to last right so appalled the most console and and squirted create a string years so string equals happy birthday now reserved our sessions and you sir john paul may enlist the stresses out so was create a user you goals you should not versed in the schools are part on dope and from there we can't hide florida dot com for passenger spring they then we can also pass and our user uses the user and now we have happy birthday to go tobacco rare notifications weekend take our notification here and is simply changes from users to user died full name and or down so when i read it to render the string here though just want to pass and the floor covered the string and then the parameters are you what to pass through and you will recognize it and then call on the attributes but if this little bit further and say that in addition to destroying the full name the user also want to say you're now however many years old a weekend in bed by adding and a another straying into our motto it's a better model was created a another string we're we're just like awaiting ph taking the date that they will not be here minus the birthday by ear and this will return the person's age the crux of backing her console here weekend just hide happy birthday user not full name you're no use in that age years old so what's been said that's true and then let's go back up to or florida or those without passing in any additional variables here we're just so passing in the user then it says happy birthday john goodman up thirty five years old totally recommend a ticket to get up it because there are many other things a duty in trade relations where are all in this relations so the user as i applaud also come country and we create the relationship here the country has it's own court definition of the name that the ot in the current state and even see here where you then reference user that country that name for saying something like what is most welcome to germany there's also a lot what other different open for matters the news today we dislike of the strings but there are some other options a media with new merits many years until then values eighteen years ago when the value or tripling the value the rays they it in time stamps you can also create your own for matters that are matters here like at five inches create a passing your values and then at the number five two and so there's several different options they have here check out the documentation and see if he can come up with some pretty cool stuff here are the queue for watching this episode