小编Ryd*_*use的帖子

Carrierwave文件删除

我再次需要你的帮助.现在我需要了解如何删除Carrierwave上传的文件(在我的情况下 - 图像).

models/attachment.rb:

class Attachment < ActiveRecord::Base
  belongs_to :attachable, :polymorphic => true
  attr_accessible :file, :file
  mount_uploader :file, FileUploader
end
Run Code Online (Sandbox Code Playgroud)

models/post.rb:

class Post < ActiveRecord::Base
  attr_accessible :content, :title, :attachments_attributes, :_destroy
  has_many :attachments, :as => :attachable
  accepts_nested_attributes_for :attachments
end
Run Code Online (Sandbox Code Playgroud)

*views/posts/_form.html.erb:*

<%= nested_form_for @post, :html=>{:multipart => true } do |f| %>
  <% if @post.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
      <% @post.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div> …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails carrierwave

5
推荐指数
3
解决办法
1万
查看次数

仅显示帖子中的一些单词作为预览

我正在使用Ruby on Rails 3.2.1和模型@post.问题是我想在我的第一个应用页面上只显示第一段或某些单词,如预览,而不是所有内容.我怎么能这样做?

指数:

<% @posts.each{|posts| %>
        <h1 class="title"><%= link_to posts.title, posts %></h1>
            <p class="byline" style="text-align: right; font-weight: bold;">Raksts izveidots: <%= posts.created_at.utc.strftime("%d.%m.%Y") %></p>
            <div class="entry">
                <p><%= raw posts.content %></p>
            </div>
        <p class="meta"><a href="#" class="more">Read More</a> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <a href="#" class="comments">Comments</a> (33)</p>           
    <% } %>
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1

4
推荐指数
3
解决办法
3674
查看次数