Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess Information from an associated model in an iterator block
    primarykey
    data
    text
    <p>On a user profile page, I want to show the "reviews" that that user has as well as "review requests". I currently have it set up where listing review requests works, like this:</p> <pre><code> def show @user = User.find(params[:id]) @review_requests = @user.review_requests.paginate(page: params[:page]) end </code></pre> <p>and the view:</p> <pre><code> &lt;ol class="review_request"&gt; &lt;%= render 'user_review_requests' %&gt; &lt;/ol&gt; </code></pre> <p>with partial:</p> <pre><code> &lt;% @review_requests.each do |review_request| %&gt; &lt;li&gt; &lt;span class="description"&gt; &lt;%= review_request.description %&gt; &lt;/span&gt; blah blah blah....(there's more of much the same) @reviews = @user.reviews.paginate(page: params[:page]) </code></pre> <p>I also want to show reviews, but the thing is, a lot of the information about the review I want to show is actually stored in the ReviewRequest model. So doing this wouldn't work:</p> <p>add to the show controller:</p> <pre><code>@reviews = @user.reviews.paginate(page: params[:page]) </code></pre> <p>and the iterator block:</p> <pre><code>&lt;% @reviews.each do |review| %&gt; &lt;li&gt; &lt;span class="description"&gt; &lt;%= review.review_request_id.description %&gt; &lt;/span&gt; </code></pre> <p>How can I access information from the ReviewRequest model that is associated with each connected review so I can show it on the profile page.</p> <p>BTW - review requests have_many reviews and reviews belong_to review requests</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload