实用 View Snippet

1. 显示简介

<%= simple_format(truncate(toy.description, 95) + link_to("More Info", toy)) %>


2. link_to_unless_current 简化代码

<% if @type != "hot" %>
            <%= link_to "热门餐厅", provience_city_path(@city, :type => "click_count")%>
        <% else %>
            <strong>热门餐厅</strong>
        <% end %>


可以如下简化

<%= link_to_unless_current("热门餐厅", provience_city_path(@city, :type => "click_count")) do
                    "<strong>热门餐厅</strong>"
                end
            %>


3.
...

你可能感兴趣的:(java,Ruby)