David Sousa
2009-Jul-21 14:47 UTC
Evaluating Ruby code that is in a sting, how do I do it?
Hello there, I have a code like. ... items = entries.map { |entry| content_tag("li", mask, :id => "#{entry.id}")} ... I want to evaluate the ruby code in the string mask on the fly... it content is: "#{entry.name} - #{entry.state.name}/#{entry.country.name}" I have tried "eval mask" but with no success. thanks, David Sousa -- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-Jul-21 16:08 UTC
Re: Evaluating Ruby code that is in a sting, how do I do it?
On Jul 21, 3:47 pm, David Sousa <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello there, > > I have a code like. > > ... > items = entries.map { |entry| content_tag("li", mask, :id => > "#{entry.id}")} > ... > > I want to evaluate the ruby code in the string mask on the fly... it > content is: > "#{entry.name} - #{entry.state.name}/#{entry.country.name}" > > I have tried "eval mask" but with no success. >Well eval is the method that evaluates code for you. In what way did it not work ? Fred> thanks, > David Sousa > -- > Posted viahttp://www.ruby-forum.com/.
David Sousa
2009-Jul-21 17:16 UTC
Re: Evaluating Ruby code that is in a sting, how do I do it?
When I try to do: items = entries.map { |entry| content_tag("li", "#{eval(mask)}", :id => "#{entry.id}")} or items = entries.map { |entry| content_tag("li", eval(mask), :id => "#{entry.id}")} I get nil as result. David Sousa -- Posted via http://www.ruby-forum.com/.
David Sousa
2009-Jul-22 23:57 UTC
Re: Evaluating Ruby code that is in a sting, how do I do it?
Hello,> > I get nil as result. >I was constructing the string in a wrong way. The cold should look like this for the :with option: :with => "value + ''&search='' + element.value + ''&field='' + ''name'' + ''&mask='' + ''entry.name \+ \" - \" \+ entry.state.name\+\"\/\"\+entry.country.name''" Regards, David Sousa -- Posted via http://www.ruby-forum.com/.