【问题标题】:Paperclip with rails 3.1 error with routes带有rails 3.1的回形针路线错误
【发布时间】:2012-01-20 19:05:18
【问题描述】:

所以我按照这里的说明进行操作:http://doganberktas.com/2010/09/14/amazon-s3-and-paperclip-rails-3/

在我的个人资料模型中,我有:

  attr_accessor  :pic_file_name (this was requested on first attempt)
  has_attached_file :pic,
       :styles => {
       :thumb=> "100x100#",
       :small  => "400x400>" },
     :storage => :s3,
     :s3_credentials => "#{Rails.root}/config/s3.yml",
     :path => "/:style/:id/:filename"

我的路线中有资源 :profiles。

我的观点如下:

<%= form_for :profile, @profile, :url => profile_path, :html => { :multipart => true } do |f| %>
<%= f.file_field :pic %>
<%= f.submit :class => "button-style", :value => "Upload File" %>
<% end %>

当我查看页面时,我收到此错误:没有路由匹配 {:action=>"show", :controller=>"profiles"}。虽然我可以向你保证,我有一个带有显示操作的配置文件控制器。

如果我将视图更改为

<%= form_for :profile, @profile, :url => @profile, :html => { :multipart => true } do |f| %>
<%= f.file_field :pic %>
<%= f.submit :class => "button-style", :value => "Upload File" %>
<% end %>

它告诉我我的参数数量错误(3 对 2)

如果我将视图更改为

<%= form_for @profile, :url => profile_path, :html => { :multipart => true } do |f| %>
<%= f.file_field :pic %>
<%= f.submit :class => "button-style", :value => "Upload File" %>
<% end %>

页面加载完毕,我可以上传图片。但是稍后尝试使用以下方法打印它:

给了我:/pics/original/missing.png(和 profile.pic.url 一样)

【问题讨论】:

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


    【解决方案1】:

    这似乎太愚蠢了(因为上面对我有用)-但这解决了它:

    将视图更改为:

    <%= form_for(@profile, :html => { :multipart => true }) do |f| %>
    

    【讨论】:

      【解决方案2】:

      感谢您的解决方案。顺便说一句,

      <%= form_for (@profile, :html => { :multipart => true }) do |f| %>
      

      不适合我,但是

      <%= form_for(@profile, :html => { :multipart => true }) do |f| %>
      

      确实有效。我在form_for 之后的空间似乎破坏了一些东西,并且可能是我的问题的原因。

      【讨论】:

      • 这会调用 m 并带有两个参数:m(a, b)。这是一个语法错误,因为括号将被视为将a, b 组合成一个(无效)表达式:m (a, b)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-21
      相关资源
      最近更新 更多