갤러리 모델과 애셋 모델이있는 사진 갤러리가 있습니다.accepts_nested_attributes_for - 기본 모델에서 파괴 방지?
class Gallery < ActiveRecord::Base
attr_accessible :gallery_name, :description, :assets_attributes
has_many :assets, :dependent => :destroy
accepts_nested_attributes_for :assets, :allow_destroy => true
def find_featured_image
assets.featured
end
def find_only_featured
assets.only_featured
end
class Asset < ActiveRecord::Base
belongs_to :gallery
has_attached_file :image,
:styles => {
:thumb => '150x150#',
:medium => '300x300>',
:large => '600x600>'
}
def self.featured
where(:featured => true).limit(1)
end
scope :only_featured, where(:featured => true)
end
end
내가 내 갤러리 양식을 통해 자산을 파괴 할 수 있어요,하지만 난 갤러리 자체를 파괴 할 때, 나는 단순히 아무 확인 통지 표시보기로 리디렉션 오전 : 아래를 참조하십시오.
def destroy
@gallery = Gallery.find(params[:id])
@gallery.destroy
respond_to do |format|
format.html { redirect_to(galleries_url) }
format.xml { head :ok }
end
내가 모델을 만들 필요가 일부 변화가 : 나는 표준 발판으로 작성되는 방법을 파괴 사용하고
<div id="gallery">
<div class="headers"><h1>MDN Photo Gallery</h1></div></br>
<% @galleries.each do |gallery| %>
<div id="gallery_wrap">
<div id="gallery_left">
<div id="gallery_head"><h2><%= gallery.gallery_name %></h2></div>
<div id="gallery_desc"><%= gallery.description %></div>
</div>
<div id="gallery_rt">
<div id="gallery_featured">
<% for asset in gallery.assets.featured %>
<%= link_to(image_tag(asset.image.url(:medium)), asset.image.url(:large), :class => "fancybox", :rel => gallery.id) %>
<% end %>
</div>
<div id="gallery_photos">
<% for asset in gallery.assets %>
<%= link_to(image_tag(asset.image.url(:thumb)), asset.image.url(:large), :class => "fancybox", :rel => gallery.id) %>
<% end %>
</div>
<td><%= link_to 'Show', gallery %></td>
<td><%= link_to 'Edit', edit_gallery_path(gallery) %></td>
<td><%= link_to 'Destroy', gallery, :confirm => 'Are you sure?', :method => :delete %></td>
</div>
</div>
</br>
<% end %>
<br />
<%= link_to 'New Gallery', new_gallery_path %>
</div>
: 여기
은 내 양식입니까? 파괴 방법? 다른 것? 중첩 모델의 부모를 삭제할 수 있으려면?미리 감사드립니다. 아이디어가 있으십니까?
레일스의 .js 라이브러리가 이것을 담당하고 있는지 알고 계십니까? 아마도 javascript의로드 순서에는 이와 관련이 있습니다. –
어떤 레일 버전을 사용하고 있습니까? 3.1 이전에 jQuery 지원을 설치했거나 기본 프로토 타입 지원을 사용하고 있습니까? –
v3.0.3을 사용 중입니다. JQuery 지원을 설치할 필요가 없다. 기본 Prototype 지원에 JQuery를 추가했습니다. 나를 연결할 수있는 링크가 있습니까? 감사! –