사용자의 사용자 계정과 연결된 여러 사진을 추가하는 기능을 추가하고 싶습니다.레일스 - 모델의 일부분만을위한 update_attributes; 파일 업로드
나는 다음과 같은 클래스가 :
class User < ActiveRecord::Base
has_many :assets
accepts_nested_attributes_for :assets
end
class Asset < ActiveRecord::Base
belongs_to :assetable, :polymorphic => true
belongs_to :user
end
난 그냥 업로드 이미지 기능이있는 화면을 갖고 싶어를 :
def add_profile_picture
@user=User.find(params[:id])
1.times {@user.assets.build}
end
형태 : 내가 제출
<%= form_for @user do |u| %>
<%= u.fields_for :assets do |asset| %>
<%= asset.file_field :asset %>
<%= asset.text_field :description %><br />
<% end %>
<%=u.submit %>
<% end %>
id 값이 development.log에서 ok로 표시됩니다.
"id"=>"1"
하지만 오류 얻을 :
정의되지 않은 메서드`update_attributes '무기 호에 대한 : 난 그냥 자산 필드를 가지고 있기 때문에 NilClass
를, 내가해야 할 특별한 있나요? 또한, belongs_to : 사용자가 존재하기 때문에 문제가 발생할 수 있습니까? 기본적으로 :
아무 도움이됩니다. Rails 양식을 많이 사용하지 마십시오.
들으
편집 # 1
class UsersController < ApplicationController
def add_profile_picture
@user=User.find(params[:id])
1.times {@user.assets.build}
end
들으
컨트롤러의 관련 작업 코드를 붙여 넣을 수 있습니까? –
이 작업은 위의 작업에서 수행되었습니다. 응답은 thx – timpone