0

Each subject has many pages and each page has many versions. On the show subject page for the owner of that subject, I want the user to be able to update all the pages and versions on that page. However, I get this error:

undefined method `versions' for nil:NilClass

My show page:

%h1
  = @subject.title
%h3 Subject Synopsis
%p
  = @subject.synopsis

- @subject.pages.each do |p|
    %h6
      = p.number
      = ": " + p.title
    %p
      = p.synopsis
    %table
      %tbody
        - p.versions.each do |v|
          %tr
           %td v.number
           %td v.create_at
    = render 'versions/form'

Versions form:

= simple_form_for [@page, @page.versions.build] do |f|
  = f.input :number, placeholder: 'Number', label: false
  = f.text_area :content, placeholder: 'Content', label: false
  = f.button :submit
8
  • can you post controller too? Commented Mar 2, 2016 at 5:03
  • Done. I think it's all wrong... Commented Mar 2, 2016 at 5:54
  • where is your show page action in your controller? Commented Mar 2, 2016 at 5:57
  • I am not able to see show action in your pages controller Commented Mar 2, 2016 at 6:02
  • There is none for pages because the pages don't contain the content Commented Mar 2, 2016 at 6:09

2 Answers 2

2
- @subject.pages.each do |p|
        %h6
          = p.number
          = ": " + p.title
        %p
          = p.synopsis
        %table
          %tbody
            - p.versions.each do |v|
Sign up to request clarification or add additional context in comments.

2 Comments

what is the difference between your code and the code which is pasted in question?
the question has been updated since i posted this answer
0

I wasn't passing through the loop variable. Answer is:

= render 'versions/form', p: p


= simple_form_for [p, p.versions.build] do |f|

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.