У меня есть следующие классы:
class VideoChannel < ActiveRecord::Base
#Associations
belongs_to :video_playlist, :dependent => :destroy
VideoChannel.video_playlist_name
delegate :name, :id, :list_type, :list_id, :manual, :to => :video_playlist, :prefix => true
#validations
validates_presence_of :name
#After Functions
def after_create
video_playlist = VideoPlaylist.new(:name => self.name,
:list_type => "VideoChannel",
:list_id => self.id)
video_playlist.save
end
И:
class VideoPlaylist < ActiveRecord::Base
belongs_to :list, :polymorphic => true
has_many :video_channels, :dependent => :destroy
delegate :name, :id, :description, :to => :video_channel, :prefix => true
end
Я пытаюсь использовать функцию делегата Rails для создания ссылки на странице VideoChannel, которая позволяет мнечтобы создать ссылку на список воспроизведения видео и редактировать там содержимое.Таким образом, ассоциация существует, и вы можете редактировать списки воспроизведения, просматривая раздел списков воспроизведения, но мы хотим объединить их.Я не могу понять это.Я также очень новичок в Rails, все еще работаю с руководствами и т. Д.
Редактировать: Вот код вида
<%= link_to '<span class="pen icon"></span>Edit',
content_url(:controller =>"video_playlists", :id => channel.video_playlist_id, :action => "edit"),
:class => "button right" %>
Вот соответствующие части контроллеров:
class VideoChannelsController < ApplicationController
# GET /videochannels
# GET /videochannels.xml
def index
@video_channels = VideoChannel.roots(:order => 'order_num')
@video_channels_parents = @video_channels.group_by {:parent_id}
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @video_channels }
end
end
# GET /videochannels/1
# GET /videochannels/1.xml
def show
@video_channel = VideoChannel.find(params[:id], :order => 'order_num')
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @video_channel }
end
end
конец
class VideoPlaylistsController < ApplicationController
# GET /video_playlists
# GET /video_playlists.xml
def index
if !params[:with].nil?
@video_playlists = VideoPlaylist.find(:all, :conditions => {:list_type => 'VideoShow'})
else
@video_playlists = VideoPlaylist.find(:all, :conditions => {:list_type => 'Section'})
end
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @video_playlists }
end
end
# GET /video_playlists/1
# GET /video_playlists/1.xml
def show
@video_playlist = VideoPlaylist.find(params[:id], :include => [{:video_video_playlists => :video}, {:videos => :asset}, {:videos => :content_image}])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @video_playlist }
end
end
end