将Paperclip集成到Rails中

问题描述 投票:1回答:1

我是一个新的Rails用户,并尝试将Paperclip集成到我的应用程序中。当我点击我的应用程序中的“新帖子”按钮时,我收到以下错误消息,此时基本上是一个博客。

SyntaxError in Posts#new

Showing /Users/blanecordes/rails_projects/BoxScoreBuzz/app/views/posts/_form.html.erb where line #1 raised:

compile error
/Users/blanecordes/rails_projects/BoxScoreBuzz/app/views/posts/_form.html.erb:1: syntax error, unexpected tASSOC, expecting kEND
...end=  form_for(@post), :html=> {:multipart => true} do |f| @...
                              ^
/Users/blanecordes/rails_projects/BoxScoreBuzz/app/views/posts/_form.html.erb:1: syntax error, unexpected kDO, expecting kEND
...html=> {:multipart => true} do |f| @output_buffer.safe_conca...
                              ^
/Users/blanecordes/rails_projects/BoxScoreBuzz/app/views/posts/_form.html.erb:35: syntax error, unexpected kENSURE, expecting $end
Extracted source (around line #1):

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

这是我当前的_form.html.erb代码

<%= 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>
  <% end %>

  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :title %><br />
    <%= f.text_field :title %>
  </div>
  <div class="field">
    <%= f.label :content %><br />
    <%= f.text_area :content %>
  </div>
  <div class="field">
    <%= f.label 'Photo' %><br />
    <%= f.file_field :photo %><br />
  </div>
<div class="actions">
    <%= f.submit %>
  </div>
<% end %>
paperclip
1个回答
4
投票

尝试将_form.html.erb中的第一行更改为:

<%= form_for(@post, :html=> {:multipart => true}) do |f| %>
© www.soinside.com 2019 - 2024. All rights reserved.