新しいオブジェクトとそれに関連する各イラストをWebページに表示したいと思います。1.小説の関連イラストを取得するためのコードを適切に作成する方法がわかりません。2.イラストオブジェクトの属性を正しく参照する方法がわかりません。3.私のエラーは無関係なものが原因である可能性があると思います。
新規モデル:
Class Novel < ActiveRecord::Base
has_many :illustrations
attr_accessible :id, :name, :author, :edition, :publisher, :publication_city, :publication_date, :illustrations
validates :id, uniqueness: true, presence: true
validates :name, :author, :edition, :publisher, :publication_city, :publication_date, presence: true
end
イラストモデル:
class Illustration < ActiveRecord::Base
belongs_to :novel
attr_accessible :id, :illustrator, :image_url,
:image_thumbnail_url, :name, :source, :tags,
:description, :novel_id
validates :id, uniqueness: true
validates :name, :source, presence: true
validates :image_url,
format: { with: %r{\.{gif|.jpg|.png}\Z}i,
message: 'must be a URL for .gif, .jpg, or .png'}
validates :image_thumbnail_url,
format: { with: %r{\.{gif|.jpg|.png}\Z}i,
message: 'must be a URL for .gif, .jpg, or .png'}
validates :illustrator, :tags, :description, presence: true
end
新規インデックスクラス:
<% if notice %>
<p id="notice"><%= notice %></p>
<% end %>
<h1 style="padding-left:25px">Archive Overview</h1>
<% @novels.each do |novel| %>
<%= illustrations = novel.map(&:illustration) %>
<div class="row">
<div class="span3" style="padding:0px 0px 25px 25px">
<%= link_to novel.name, novel %>
</div>
<div class="span4">
<p><%= novel.author%></p>
<p><%= novel.publisher %></p>
<p><%= novel.publication_date %></p>
<div class="span5">
<ul>
<% for illustrations.each do |illustration| %>
<li><%= illustration.name %></li>
<% end %>
</ul>
</div>
</div>
</div>
<% end %>
illustrations.eachのforループ構文の任意の組み合わせで発生するエラー:
SyntaxError in Booklist#index
Showing /home/joe/Documents/workspace/archive/app/views/booklist/index.html.erb where line #21 raised:
/home/joe/Documents/workspace/archive/app/views/booklist/index.html.erb:21: syntax error, unexpected '\n', expecting tCOLON2 or '[' or '.'
Extracted source (around line #21):
18: <ul>
19: <% for illustrations.each do |illustration| %>
20: <li><%= illustration.name %></li>
21: <% end %>
22: </ul>
23: </div>
24: </div>
Trace of template inclusion: app/views/booklist/index.html.erb
Rails.root: /home/joe/Documents/workspace/archive