【问题标题】:Linking to Paperclip URL from ActiveAdmin Record in Rails从 Rails 中的 ActiveAdmin 记录链接到 Paperclip URL
【发布时间】:2023-03-05 06:18:01
【问题描述】:

我在 Rails 3.1 应用程序中同时使用 ActiveAdmin 和 Paperclip。在我的用户模型中,我使用的是 Paperclip,因此用户可以上传 PDF。我想要做的是显示一个指向 PDF 文件的链接,而不是在表格中看到分段的回形针字段(即 file_name、content_type、file_size)。

我的 user.rb 模型:

has_attached_file :letter 
validates_attachment_content_type :letter, :content_type => ['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'application/pdf', 'image/tiff'], :message => "Only pdf, jpeg, gif, tiff and png files are allowed"  

ActiveAdmin 的我的 user.rb:

ActiveAdmin.register User do
  index do
    id_column
    column :username
    column :email    
    default_actions
  end
end

【问题讨论】:

    标签: ruby-on-rails-3 paperclip activeadmin


    【解决方案1】:

    你可以给它一个块。类似于:

    ActiveAdmin.register User do
      index do
        id_column
        column :username
        column :email
        column :letter do |user|
          link_to user.letter, letter_url_path
        end
        default_actions
      end
    end
    

    【讨论】:

    • 谢谢!我只需要将 url 更改为 user.letter.url(:original, false)
    猜你喜欢
    • 2014-10-23
    • 2016-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-25
    相关资源
    最近更新 更多