Ruby on Rails Tuesday, January 4, 2011

Although this will work, it seems like bad form to do this for helpers in the view.
IMO, if the helper is intended to return renderable html, it should. Simply add .html_safe to
the end of .join() in your helper --> .join(' ').html_safe

Hope this helps

On Jan 4, 2011, at 2:23 AM, sameera wrote:

> Hi Ravi,
>
> Its because with rails3 they have implemented script safety by
> default. If you want to print html/script codes you need to
> explicitly declare it. try this
>
> <%= raw project_title_links(project) %>
>
> should work
>
> cheers
>
> sameera
>
> On Jan 3, 11:10 pm, Ravi Kukreja <li...@ruby-forum.com> wrote:
>> Hello:
>> I am learning to use Helpers in Rails 3.
>> I have a project model with 'Name' attribute in it. I want to display
>> all the Projects with a 'Show' link next to it. The Problem is instead
>> of displaying a link for 'Show' it is displaying the html(<a
>> href="/projects/1"><img alt="Show"
>> src="/images/icons/show.png?1285276800" /></a>
>>
>> CODE:
>> --Here is my app/views/projects/index.html.erb
>>
>> <title> <p> Projects </p></title>
>> <%= render @projects %>
>>
>> --app/views/projects/_projects.html.erb
>>
>> <div class="project">
>> <%= project_title_links(project) %>
>> </div>
>>
>> --app/helpers/people_helper.rb
>>
>> module PeopleHelper
>> def project_title_links(project)
>> content_tag :h1 do
>> [ project.title,
>> link_to_icon('show', project)
>> ].join(' ')
>> end
>> end
>> end
>>
>> --app/helpers/application_helper.rb
>>
>> module ApplicationHelper
>>
>> def link_to_icon(icon_name, url_or_object, options={})
>> link_to(image_tag("icons/#{icon_name}.png"),
>> url_or_object,
>> options)
>> end
>>
>> end
>>
>> --
>> Posted viahttp://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment