Reputation: 3132
How do I write a function:
mymessage("2011-02-27", "Aravind")
that will return
Hello Aravind, you entered the following date: Friday February 27, 2011
Upvotes: 0
Views: 95
Reputation:
def mymessage(date,name)
"Hello #{name}, you entered the following date: #{date}"
end
Upvotes: 1
Reputation: 48606
Well, Rails works with a model view controller design pattern, so ideally, to do this, you would need to create code in all three components.
For simplicity, i will assume that you want to do this inside a helper, and i will only write the method. First of all, take a look at how you can construct the date :
ROR + Ruby Date in Different Format
Now, your function could be like :
def mymessage(the_date, name)
formatted_date = the_date.to_time.strftime("%A %B %d, %Y")
"Hello #{name}, you entered the following date: #{formatted_date}"
end
Upvotes: 4