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 7092131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:16:30+00:00 2026-05-28T08:16:30+00:00

I am working on a multisite for a client for a skateboarding website. So

  • 0

I am working on a multisite for a client for a skateboarding website. So far everything is great but I am starting to get stuck on the whole partial thing. I have a site and site has_many :albums(Album also belongs to site) but when I try to render albums from a site on the sites homepage i get undefined method `model_name’ for NilClass:Class?

I have am trying to render albums/_album.html.erb on the sites/show page to display a site latest’s album on the homepage of the site.

Albums Controller

class AlbumsController < ApplicationController

  def index
    @albums = Album.all
  end

  def show
    @album = Album.find(params[:id])
  end

  def new
    @album = Album.new
  end

  def edit
    @album = Album.find(params[:id])
  end

  def create
    @album = current_site.albums.build(params[:album])

    if @album.save
     redirect_to albums_path, :notice => 'Album was successfully created.'
    end
  end

  def update
    @album = Album.find(params[:id])

    if @album.update_attributes(params[:album])
     redirect_to album_path(@album), :notice => 'Album was successfully updated.'
    end
  end

  def destroy
    @album = Album.find(params[:id])
    @album.destroy
  end
end

Sites Controller

class SitesController < ApplicationController

  def index
    @sites = Site.all
  end

  def show
    @site = Site.find_by_subdomain!(request.subdomain)
  end

  def new
    @site = Site.new
  end

  def edit
    @site = Site.find(params[:id])
  end

  def create
    @site = Site.new(params[:site])

    if @site.save
     redirect_to @site, :notice => 'Signed up!'
    end
  end

  def update
    @site = Site.find(params[:id])

    if @site.update_attributes(params[:site])
      redirect_to @site, :notice => 'Site was successfully updated.'
    end
  end

  def destroy
    @site = Site.find(params[:id])
    @site.destroy
  end
end

Site Show.html

<p id="notice"><%= notice %></p>

<p>
  <b>First name:</b>
  <%= @site.first_name %>
</p>

<p>
  <b>Last name:</b>
  <%= @site.last_name %>
</p>

<p>
  <b>Subdomain:</b>
  <%= @site.subdomain %>
</p>

<%= render :partial => 'albums/album'%>

<%= link_to 'Edit', edit_site_path(@site) %> |
<%= link_to 'Back', sites_path %>

Albums/_album.html.erb

<%= div_for @album do %>
  <h2><%= @album.title %></h2>
   <%= image_tag @album.photo.url(:small) %>
<% end %>

Am I missing something in my albums controller?

  • 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-28T08:16:31+00:00Added an answer on May 28, 2026 at 8:16 am

    In your show.html, you need to pass in the collection of albums to the render method

    <%= render :partial => 'albums/album', :collection => @site.albums %>
    

    Within the _album.html.erb partial, you need to reference the album attribute as a local attribute, like so

    <%= div_for album do %>
      <h2><%= album.title %></h2>
      ...
    

    You can read more about partials here 3.4.5 Rendering Collections

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

Sidebar

Related Questions

I've setup WP multisite got it all working, but how do I create /
I am trying to get Wordpress 3.3.1 multisite (sub-domains) working in my localhost. However,
I'm working on a JMD (Java MarkDown) (a Java port of MarkDownSharp ) but
I'm working on a regular expression in a .NET project to get a specific
I've tried to accomplish this with regex but it seems not to be working
i'm working on multisite and I'd like to share session data between two or
I have a Wordpress Multisite which was working fine until I migrated the instance
hi I'm trying to get my multisites config working, and am struggeling at the
I am using ASP.NET repeater function. Its working fine. But here all the comments
Our company is trying to transition to WordPress Multisite but we have several issues

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.