user3437721
user3437721

Reputation: 2279

Rails - return html black from model

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

Upvotes: 1

Views: 557

Answers (1)

tiktak
tiktak

Reputation: 1811

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.

Upvotes: 1

Related Questions