我有一个使用Wicked Wizard表单设置的应用程序来创建一个新帖子。 最后一步允许用户将图片上传到他们的帖子。 对于图像处理我正在使用Carrierwave和Fog(因为我在heroku上托管该站点,我使用Amazon S3进行存储)。 它一切正常,但上传到Amazon S3非常慢。
在Ryan Bates上传到Amazon S3 railscast(http://railscasts.com/episodes/383-uploading-to-amazon-s3)之后,我尝试了Carrierwave_Direct(https://github.com/dwilkie/carrierwave_direct)以加快向Amazon S3的缓慢上传速度。
然而,当这样做时,我收到一个错误:
NoMethodError in PostSteps#show
Showing
/Users/petersonneveld/rails_projects/doamer/doamer2/app/views/property_steps/picture.html.erb where line #1 raised:
undefined method `direct_fog_url' for nil:NilClass
我真的不知道如何解决这个问题。有人有建议吗?非常感谢你的帮助!
在我邪恶的巫师形式的最后一步中我有
# app/views/post_steps/picture.html.erb
<%= direct_upload_form_for @uploader, url: wizard_path do |f| %>
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">
<h2>Let's post some pictures!</h2>
</div>
</div>
<div class="panel-body">
<% 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 |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-group col-md-12">
<%= f.label :image, "Upload image" %><br>
<%= image_tag(@post.image_url(:thumb)).to_s if @post.image? %>
<%= f.file_field :image %>
</div>
<div class="form-group col-md-12">
<%= f.label :remote_image_url, "or paste image URL" %>
<%= f.text_field :remote_image_url, class: "form-control" %>
<%= f.hidden_field :image_cache %>
</div>
<div class="form-group col-md-12">
<h4><%= f.check_box :remove_image %>
<span class="label label-danger">Remove image</span></h4>
</div>
<div class="form-group col-md-12">
<%= f.button "Finish", class: "btn btn-primary", data: {disable_with: "<i class='fa fa-spinner fa-spin'></i> Saving post..."} %>
</div>
</div>
</div>
<% end %>
在我的控制器中
# app/controllers/post_steps_controller.rb
class PostStepsController < ApplicationController
include Wicked::Wizard
steps :description, :picture
def show
@post = Post.find(params[:post_id])
render_wizard
end
def update
@post = Post.find(params[:post_id])
@post.update_attributes(post_params)
render_wizard @post
end
private
def post_params
params.require(:post).permit(...)
end
def redirect_to_finish_wizard(options = nil)
redirect_to @post, notice: "Thanks for submitting a post."
end
end
我的帖子控制器创建动作
# app/controllers/post_controller.rb
def create
@post = current_user.posts.build(post_params)
if @post.save
redirect_to post_steps_path(:id => "description", :post_id => @post.id)
else
render :new
end
end
答案 0 :(得分:0)
找到答案:必须更新&#39; aws-sdk&#39;宝石!