0
votes

I'm working on an app where i nested the 3 model

resources :genres do
    resources :stories do
        resources :episodes
    end
end

Meanwhile, i've been able to write the form for genres and stories as in

<%= form_for(genre) do |f| %>
 <% if genre.errors.any? %>
  <div id="error_explanation">
  <h2><%= pluralize(genre.errors.count, "error") %> prohibited this genre from being saved:</h2>

  <ul>
  <% genre.errors.full_messages.each do |message| %>
    <li><%= message %></li>
  <% end %>
  </ul>
</div>
<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>

<div class="field">
   <%= f.label :description %>
  <%= f.text_area :description %>
</div>

<div class="actions">
 <%= f.submit %>
 </div>
<% end %>

and stories

<%= form_for([@genre, @genre.stories.build]) do |f| %>
<div class="field">
    <%= f.label :title %>
    <%= f.text_field :title %>
</div>

<div class="field">
    <%= f.label :summary %>
    <%= f.text_area :summary %>
</div>

<div class="actions">
   <%= f.submit %>
   </div>
<% end %>

Can someone pls tell me how to write the form for episodes...

When i wrote this

<%= form_for([@genre.stories, @[email protected]]) do |f| %>
<div class="field">
    <%= f.label :title %>
    <%= f.text_field :title %>
</div>

<div class="field">
    <%= f.label :content %>
    <%= f.text_area :content %>
</div>

<div class="actions">
    <%= f.submit %>
</div>
<% end %>

I got this error

syntax error, unexpected tIVAR, expecting '(' [email protected], @[email protected]]) do |f| @out... ... ^ C:/Users/Adegbite/Documents/Apps/twiliste2/app/views/episodes/_form.html.erb:1: syntax error, unexpected ']', expecting keyword_end ...@[email protected]]) do |f| @output_buffer.safe_... ... ^ C:/Users/Adegbite/Documents/Apps/twiliste2/app/views/episodes/_form.html.erb:16: syntax error, unexpected keyword_ensure, expecting end-of-input

Thanks.

1
Curious if the answer I provided was helpful... - jvillian
Yes, jvillian... My bad. I dont know why i'm unable to vote up. - Lashe

1 Answers

0
votes

This:

<%= form_for([@genre.stories, @[email protected]]) do |f| %>

Should be more like:

<%= form_for([@genre, @story, @story.episodes.build]) do |f| %>

Of course, you'll have to set @genre and @story appropriately in the new action of your EpisodesController.

BTW, @genre.@stories makes no sense and is not valid. @stories is an instance variable which, presumably, contains (or would contain) one or more stories. .stories is a method call on an instance of Genre. .@stories is nothing.