1

I have a method in my model which is called in a modal like this:

<div class="col-sm-9"><%= @notification.notifier_context %></div>

In this method, I want to return some HTML like this, which has a rails helper path in it.

context = "<td><%= link_to('link', account_item_path(@item.account, @item))%></td>".html_safe

But its just out-putting the string as is. How can I get it evaluated to HTML proper?

Thanks

user3437721
  • 1,869
  • 4
  • 22
  • 51

1 Answers1

1

Try:

"<td>#{link_to('link', Rails.application.routes.url_helpers.account_item_path(@item.account, @item))}</td>".html_safe

String is not erb template so you can't use <%= %> syntax. Also it's great idea to use helpers (with content_tag) or partials for that. Also if you need to use routes inside model class, read following answer.

Community
  • 1
  • 1
tiktak
  • 1,741
  • 2
  • 24
  • 44