我有一個Rails 4應用程序,我使用CarrierWave從url獲取圖像。在我的form_for url傳入params就好了,但我似乎無法獲得url的保存。當我看看最後的Stamp
保存時,remote_image_url
是nil
。我確定這很簡單,但文檔是相當可悲的。CarrierWave remote_image_url不保存
只是爲了確認;當使用表格中的f.file_field
從文件上載圖像時,CarrierWave可以很好地工作。
這裏是我的代碼:
stamp_uploader.rb
:
class Stamp < ActiveRecord::Base
mount_uploader :image, StampUploader
mount_uploader :remote_image_url, StampUploader
end
stamps_controller
:
def show
@stamp = Stamp.find(params[:id])
end
def new
@stamp = Stamp.new
end
def create
@stamp = Stamp.create(stamp_params)
if @stamp.save
flash[:success] = "Thanks for your submission!"
redirect_to root_path
else
render :new
end
end
private
def stamp_params
params.require(:stamp).permit(:image, :remote_image_url)
end
new.html.erb
:
<%= form_for @stamp do |f| %>
<%= image_tag(current_user.image) %>
<%= f.label :remote_image_url, "Upload Image" %>
<%= f.text_field :remote_image_url, value: current_user.image %>
<%= f.submit %>
<% end %>
schema.rb
:
create_table "stamps", force: :cascade do |t|
t.string "image"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "remote_avatar_url"
t.string "remote_image_url"
end
PARAMS:
=> {"utf8"=>"✓",
"authenticity_token"=>"rA8KaI+bG5ygldeQC2n00z3BuEfiA0xO4tukUUL3tvG19G7WQCuMMqwzwWzWSMbKlT+2W5KsJYF4Q/lXg9OHeA==",
"stamp"=>{"remote_image_url"=>"https://graph.facebook.com/10157057736060574/picture?width=1000&height=1000"},
"commit"=>"Create Stamp",
"controller"=>"stamps",
"action"=>"create"}
你可以發佈你的控制器收到的參數(從你的軌道控制檯)? – RichardAE
當然,添加到主要問題 – BillyBib