Perhaps it is something basic as a beginner I am. I have the following:
controllers:
main
editions
works
composers
main:
class MainController < ApplicationController
def welcome
@composers = Composer.find(:all).sort_by {|c| [c.last_name,
c.first_name]}
end
end
works - editions - composers all have normal scaffold generated
methods(CRUD)
Models: - relavent info (hopefully) provided:
class Composer < ActiveRecord::Base
attr_accessible :first_name, :last_name
has_many :works, dependent: :destroy
before_destroy :ensure_not_referenced_by_any_work
…
def editions
works.map {|work| work.editions}.flatten.uniq
end
…
end
class Edition < ActiveRecord::Base
validates :publisher_id, :description, :price, :year, presence: true
has_many :environments
has_many :works, through: :environments
belongs_to :publisher
has_many :orders
attr_accessible :descripition, :price, :work_id, :year, :title,
:publisher_id
…
end
class Work < ActiveRecord::Base
attr_accessible :composer_id, :title
belongs_to :composer
has_many :environments
has_many :editions, :through => :environments
has_many :instruments, :through => :environments
…
end
class Environment < ActiveRecord::Base
attr_accessible :instrument_id, :name, :work_id, :edition_id
belongs_to :work
belongs_to :instrument
belongs_to :edition
end
I want the following partial to be shown in the Main#Welcome view:
partial is located in the composer view folder:
Editions List
-
<% @composer.editions.map do |edition| %> #line 3 in error below
- <%= link_to_edition_title(edition)%> <% end %>
The link_to_edition_title(edition)… may not be relavent but here it is
in
the edition helper module:
def link_to_edition_title(edition)
link_to(edition.nice_title, edition_path(edition))
end
My limited knowledge believes the call to the partial should work and
indeed it does if done like this within the Composer#Show view:
<%= render “edition” %>
However, when I make the partial call from the Main#Welcome view like
this:
The Main#Welcome view:
<%= render :partial => “composers/edition” %>
It results in this error:
NoMethodError in Main#welcome
Showing *
/Users/akkdio/railsapps/rails_3/ruby_for_rails/r4r_music/r4r_music1/app/views/composers/_edition.html.erb
- where line #3 raised:
undefined method `editions’ for nil:NilClass
This is the first linke of the trace:
app/views/composers/_edition.html.erb:3:in
`_app_views_composers__edition_html_erb__1574837102347920251_2165688820’
If more is needed please let me know. Appreciate any nudge as to how I
would change the partial or somehow get the editions method to be
recognized in this call - the idea is to be able to share the partial
across the application.
Thanks for your help,
Andrew