0

我有一个嵌套表格(见下文)

模型艺术家(艺术家是用户)

has_many :art_works
  has_many :canvases
  accepts_nested_attributes_for :art_works //artworks is what im currently working on
   accepts_nested_attributes_for :canvases

控制器 art_works

    def new
    @artist = Artist.find(params[:artist_id])
    @artwork = @artist.art_works.build
    respond_to do |format|
          format.html # new.html.erb
          format.json { render json: @artwork }
        end
      end
  def create
    @artwork = ArtWork.new(params[:artwork])
    respond_to do |format|
      if @artwork.save
        format.html { redirect_to @artwork, notice: 'artwork was successfully created.' }
        format.json { render json: @artwork, status: :created, location: @artwork }
      else
        format.html { render action: "new" }
        format.json { render json: @artwork.errors, status: :unprocessable_entity }
      end
    end
  end

艺术品视图_form

<%= form_for(@artwork, :url => artist_art_works_path(current_artist) :multipart => true) do |f| %>
<p>
    <%= f.file_field :art %>
</p>
<p>
    <%= f.submit %>
</p>
<% end %>

我很肯定这会起作用,但我假设我的 :url 不正确?我不确定它还会是什么。下面是我的艺术品路线我嵌套这些东西的原因是因为艺术家可以将艺术品上传到艺术品模型中,这个想法是在一件艺术品中包含几件艺术品(就像一张专辑里面有很多图像)

artist_art_works GET    /artists/:artist_id/art_works(.:format)                          art_works#index
                              POST   /artists/:artist_id/art_works(.:format)                          art_works#create
          new_artist_art_work GET    /artists/:artist_id/art_works/new(.:format)                      art_works#new
         edit_artist_art_work GET    /artists/:artist_id/art_works/:id/edit(.:format)                 art_works#edit
              artist_art_work GET    /artists/:artist_id/art_works/:id(.:format)                      art_works#show
                              PUT    /artists/:artist_id/art_works/:id(.:format)                      art_works#update
                              DELETE /artists/:artist_id/art_works/:id(.:format)                      art_works#destroy

非常感谢您的帮助。(对不起菜鸟)

4

1 回答 1

1

你少了一个逗号。是的,错误消息没有那么有用。

@artwork, :url => artist_art_works_path(current_artist) :multipart => true

对比

@artwork, :url => artist_art_works_path(current_artist), :multipart => true
于 2013-06-11T03:31:28.127 回答