Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6087207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:50:40+00:00 2026-05-23T11:50:40+00:00

I have the following classes: class VideoChannel < ActiveRecord::Base #Associations belongs_to :video_playlist, :dependent =>

  • 0

I have the following classes:

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

And :

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

I’m trying to use the Rails Delegate function to create a link in the VideoChannel page that allows me to to link to the Video Playlist and edit the contents there. So the association is there and You can currently edit the playlists by going through the playlists section but we want to combine them. I can’t seem to figure this out. Im also very new to Rails, still working through the guides etc.

Edit: Here’s the view code

<%= link_to '<span class="pen icon"></span>Edit',
      content_url(:controller =>"video_playlists", :id => channel.video_playlist_id, :action => "edit"),
      :class => "button right" %>

Here are teh relevant pieces of the controllers:

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

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:50:41+00:00Added an answer on May 23, 2026 at 11:50 am

    Where did the line

    VideoChannel.video_playlist_name
    

    Come from? What’s it doing? You’re also calling a method on the class not an instance (sort of – Ruby isn’t quite like this, but it’s enough to explain).

    Anyway:

    Delegate is really for avoiding lots of train wreck code like this:

    fred.jim.bill.xxx
    

    You’ve said that they belong to each other – the relationships look like they’re the wrong way round. Why are you creating the parent from inside the child? How are you going to have many video channels belonging to a given playlist?

    I think you need to look at build and the relationship names. To gat past me maybe misunderstanding your model, lets have switch to a product that has many stock items:

    class Product < ActiveRecord::Base
      has_many :stock_items
    end
    
    class StockItem < ActiveRecord::Base
      belongs_to :product
    end
    

    This means that stock_item will have a column product_id.

    So, say you’re creating a product you’d do something like:

    product.stock_items.build # :whatever the params are required
    

    This automatically sets the id’s for you and means you don’t have to set id’s. Then when you do product.save it will save all the related stock items too.

    And in the view for this toy model, then if you were displaying one of the stock items, you’d use delegate to show the name of the product in the view without having to do lost of stock_item.product.name (for example).

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following classes: class Vigil < ActiveRecord::Base after_update :do_something_cool private def do_something_cool
I have the following two classes: class Menu < ActiveRecord::Base has_many :menu_headers accepts_nested_attributes_for :menu_headers
I have a the following classes class Service < ActiveRecord::Base has_many :incidents end class
I have the following classes: class Person { public string Name { get; set;
I have the following classes: abstract class Transport{ protected String name; protected Transport(String name){
I have the following classes: class Catalog { static mapping = { id composite:['name',
I have the following classes class A{ private String name; private int value; public
Let's say I have the following classes: class Votable(models.Model): name = ... class Vote(models.Model):
Assume I have the following classes class Genre { static hasMany=[author:Author] } class Author{
I have the following classes: public class Person { public String FirstName { set;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.