Note that there are some explanatory texts on larger screens.

plurals
  1. PONew to jQuery/Ajax how can I add a user relation to creating a new review?
    primarykey
    data
    text
    <p>I have been trying to get to grips with jQuery and been following a <a href="http://railscasts.com/episodes/136-jquery" rel="nofollow">railscast</a> on adding an Ajax add review form, which works fine but I would now like to add into it the ability for a review to belong to a user as well as a venue. </p> <p><b>Reviews controller</b></p> <pre><code>def create @review = Review.create!(params[:review]) @review.venue = @venue if @review.save flash[:notice] = 'Thank you for reviewing this venue!' respond_to do |format| format.html { redirect_to venue_path(@venue) } format.js end else render :action =&gt; :new end end </code></pre> <p><b>views\reviews\create.js.erb</b></p> <pre><code>$("#new_review").before('&lt;div id="flash_notice"&gt;&lt;%= escape_javascript(flash.delete(:notice)) %&gt;&lt;/div&gt;'); $("#reviews_count").html("&lt;%= pluralize(@review.venue.reviews.count, 'Review') %&gt;"); $("#reviews").append("&lt;%= escape_javascript(render(:partial =&gt; @review)) %&gt;"); $("#new_review")[0].reset(); </code></pre> <p>I have tried changing the controller to:</p> <pre><code> def create @review = @current_user.reviews.create!(params[:review]) @review.venue = @venue if @review.save flash[:notice] = 'Thank you for reviewing this venue!' respond_to do |format| format.html { redirect_to venue_path(@venue) } format.js end else render :action =&gt; :new end end </code></pre> <p>but it just wont submit, with no errors.</p> <p>I think I have the models set correctly with belongs_to and has_many, I think this is a controller issue I'll add other code bits if needed.</p> <p><b>Development log</b></p> <pre><code>NoMethodError (undefined method `reviews' for nil:NilClass): app/controllers/reviews_controller.rb:14:in `create' </code></pre> <p>Thanks for any help!</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.
 

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