3
내 코드의 구조는 다음과 같습니다. 나는 각 cresponse에 붙어있는 비디오를 가지고 있으며, 내가 성공적으로 업로드했다고 말할 수있다. 구조체를 저장 한 후에 변환해야 할 때 문제가 발생합니다. 새로 업데이트 된 중첩 된 속성 (lesson_controller 참조)에 액세스하려고하지만 그렇게하는 방법을 모르겠습니다.레일에서 중첩 된 속성 컨트롤러에서 검색
감사합니다.
부두. 갱신
-lesson.rb
class Lesson < ActiveRecord::Base
has_one :user
has_many :comments, :dependent => :destroy
has_many :cresponses, :dependent => :destroy
acts_as_commentable
accepts_nested_attributes_for :comments, :reject_if => lambda { |a| a[:body].blank? }, :allow_destroy => true
accepts_nested_attributes_for :cresponses
여기가
class Cresponse < ActiveRecord::Base
belongs_to :lesson
attr_accessible :media, :accepted, :description, :user_id
# NOTE: Comments belong to a user
belongs_to :user, :polymorphic => true
# Paperclip
require 'paperclip'
has_attached_file :media,
:url => "/system/:lesson_id/:class/:basename.:extension",
:path => ":rails_root/public/system/:lesson_id/:class/:basename.:extension"
가 여기 내 HTML보기
<% @cresponse = @lesson.cresponses.build %>
<%= form_for @lesson, :html => { :multipart => true } do |f| %>
<td class="list_discussion" colspan="2">
<div class="field">
<%= f.fields_for :cresponses, @cresponse, :url => @cresponse, :html => { :multipart => true } do |builder| %>
Upload : <%= builder.file_field :media %><br />
Description : <%= builder.text_field :description %>
<%= builder.hidden_field :user_id , :value => current_user.id %>
<% end %>
</div>
</td>
그리고 여기 lesson_controller.rb의 cresponse.rb입니다
def update
@lesson = Lesson.find(params[:id])
respond_to do |format|
if @lesson.update_attributes(params[:lesson])
**if @lesson.cresponses.** <-- not sure how to find the cresponse that I need to convert
puts("Gotta convert this")
end