开发者

Make the view render an html substring

开发者 https://www.devze.com 2022-12-13 05:33 出处:网络
I\'ve got the following controller def detail @book = get_book_details(params[:asin]) respond_to do |format|

I've got the following controller

def detail
    @book = get_book_details(params[:asin])

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @booklists }
    end
end

the unbundle lib get_book_details(asin), return a "book = Hash.new" like this:

book[:title]
book[:editorial_reviews] 
book[:total_reviews] 
... 

and so on. In the view, I get the following

<%= h @book[:editorial_reviews]%>

The problem is that the content of @book[:editorial_reviews]开发者_开发百科 is actually an HTML

substring, containing some fews tags I'd like to render.

Like that, I'll get those tags into the client browser view, but not interpreted and

sanitizing the string, result in missing some formatting layout which I'd like to

display instead.

How can I make the view render that inside html tags ???

Sorry for the newbie question. Thanks in advance lgs


The h method escapes all the html tags. If you remove it, your html tags won't be escaped.
And you'll have your content appropriately formatted.

<%= @book[:editorial_reviews] %>
0

精彩评论

暂无评论...
验证码 换一张
取 消