【问题标题】:Show maximum symbols in ruby on rails?在 ruby​​ on rails 中显示最大符号?
【发布时间】:2018-06-30 19:58:04
【问题描述】:

如何显示最多 250 个符号?对于 post.description

<% @microposts.each do |post| %>
    <% a = post.had %>
    <% b = post.needs.to_f %>
    <% count = (a/b)*100 %>
      <div class="col-md-12 post card-1 card-3">
        <h3 class="pad-h3"><%= post.title %> <text class="needs"> Needs  <%= post.needs %>$</text></h3>
        <div class="row pad">
          <div class="col-md-6"><a href="/help/id<%= post.id %>"><img class="img2" src="<%= post.image1 %>">
            <h3 class="fun"><%= count %>% Funded</h3>
          </a></div>
          <div class="col-md-6"><p><%= post.description %></p></div>
        </div>
        <div class="row"><a href="/help/id<%= post.id %>" class="butt2" data-wipe="Show more information">Show more information</a></div>
       </div>
  <% end %>

Sometext SometextSometextSometextSometext Sometextv Sometextv vvvvvvSometextSometextSometextSometextSometextSometextSometextSometextSometextSometextSometextSome textSometextS dometext SometextSometextSometextSometextSometextSometextSometextSometextSometextSometextSometext

【问题讨论】:

  • 术语“symbol”在 Ruby 中具有特定的含义。你是说字符吗?

标签: ruby-on-rails ruby database each


【解决方案1】:

Rails 有 truncate text helper:

<%= truncate post.description, length: 250 %>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-24
    • 1970-01-01
    • 1970-01-01
    • 2021-11-01
    • 1970-01-01
    • 2020-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多