Arihant Godha Arihant Godha - 4 months ago 27
Ruby Question

How do I use HAML in a dynamic link?

I am trying to create a link using HAML which looks like the this

=link_to("Last updated on<%=@last_data.date_from.month %>",'/member/abc/def?month={}&range=xyz&year={}')

It is not taking the Ruby code and it is displaying that as a string

Last updated on<%=@last_data.date_from.month %>

and in the URL as well it is not taking the function

How do I pass Ruby code in URL and in the string ?


You should probably use something like this:

= link_to("Last updated on #{@last_data.date_from.month}", "/member/abc/def?month=#{}&range=xyz&year=#{}")

Note that in the second string, it's necessary to change the ' to ". Also if the link text is getting long, you can use something like this:

= link_to("/member/abc/def?month=#{}&range=xyz&year=#{}") do
  Last updated on #{@last_data.date_from.month}