を発生し、私は カントアップロード画像レールとエラーが、私は宝石「carrierwave」を使用して、私はlocalhostに画像をアップロードしたい
コードの下の絵コントローラ
class PaintingsController < ApplicationController
def index
@paintings=Painting.all
end
def new
@painting=Painting.new
end
def show
@painting=Painting.find(params[:id])
end
def create
#byebug
@painting=Painting.new(painting_params)
if @painting.save
flash[:success]="Created image in album"
redirect_to gallery_path(@painting)
else
flash[:error]="Fail!"
render 'new'
end
end
private
def painting_params
params.require(:painting).permit(:name,:gallery_id)
end
end
のような絵やギャラリーのコントローラを持っていますギャラリーコントローラ 2つのモデルファイル[OK]を
class GalleriesController < ApplicationController
def index
@galleries=Gallery.all
end
def new
@gallery=Gallery.new
end
def show
@gallery=Gallery.find(params[:id])
end
def create
@gallery=Gallery.create!(gallery_params)
redirect_to galleries_path
end
private
def gallery_params
params.require(:gallery).permit(:name)
end
end
: gallery.rb
class Gallery < ApplicationRecord
has_many :paintings
end
painting.rb
class Painting < ApplicationRecord
def access_params
params.require(:painting).permit(:gallery_id, :name, :image)
end
belongs_to :gallery, optional: true
mount_uploader :image, ImageUploader
end
それはeveryingがうまくいくが、その後、私はギャラリーにshow.html.erb上の画像を示す工程で立ち往生ようです。画像はギャラリーのコントローラでalthoughtフラッシュを示したされていない
<div id="paintings">
<% @gallery.paintings.each do |painting| %>
<div class="painting">
<%= image_tag painting.image_url.to_s %>
<div class="name"><%= painting.name %></div>
<div class="actions">
<%= link_to "edit", edit_painting_path(painting) %> |
<%= link_to "remove", painting, :confirm => 'Are you sure?', :method => :delete %>
</div>
</div>
<% end %>
<div class="clear"></div>
</div>
show.html.erbは、私がイメージを作成したことを報告し、私はショーに印刷塗装s'attributesを試した後、ウェブサイトを視察しました.html.erb
<%= @gallery.name %>
<%= @gallery.paintings.name %>
<%= @gallery.paintings.gallery_id%>
<%= @gallery.paintings.image%>
ギャラリーの名前と絵の名前のみが印刷されます。他の2つのメソッドにエラーが発生しています。
undefined method `gallery_id' for #<ActiveRecord::Associations::CollectionProxy []>
ギャラリーだけで他の人の絵の名前にアクセスすることはできませんが、なぜ私にはわからないtwo.Iは、このエラーの検索が、私は、これらの状況は私には適用と思ういけません。問題は何ですか?