私は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