Note that there are some explanatory texts on larger screens.

plurals
  1. PORails help creating ajax star rating
    primarykey
    data
    text
    <p>I am having a bit trouble creating some simple ajax rating based on these two answers. <a href="https://stackoverflow.com/questions/5033879/rails-3-rateable-model-how-to-create-ajax-rating">Rails 3 rateable model - How to create ajax rating?</a> and <a href="https://stackoverflow.com/questions/5516970/rails-ajax-rating-help-how-to-create-a-helper-method-to-display-stars">Rails ajax rating help how to create a helper method to display stars</a></p> <p>I get the following error in my kategori view:</p> <pre><code>NameError in Kategoris#show Showing C:/Rails/konkurranceportalen/app/views/kategoris/_rating.html.erb where line #2 raised: undefined local variable or method `f' for #&lt;#&lt;Class:0x3c77820&gt;:0x3c724f8&gt; Extracted source (around line #2): 1: &lt;%= form_tag url_for(controller: 'konkurrancers', action: 'rate', id: "#{vind.id}"), remote: true %&gt; 2: &lt;%= f.text_field :ratings, :size =&gt; 1, :min =&gt; 0, :max =&gt; 5, :step =&gt; 1 %&gt; 3: &lt;div class="rateit" data-rateit-backingfld="#konkurrancer_ratings" data-rateit-resetable="true"&gt; 4: &lt;/div&gt; 5: &lt;/form&gt; </code></pre> <p>My kategori show view:</p> <pre><code>&lt;h1&gt;&lt;%= @kategori.h2.force_encoding("UTF-8") %&gt;&lt;/h1&gt; &lt;div id="konkurrancer"&gt;&lt;%= render 'konkurrencer', :remote =&gt; true %&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>My konkurrencer partial:</p> <pre><code>&lt;div id="tabel"&gt; &lt;table id="tabel1" border="0" bordercolor="#000000" style="background-color:#FFFFFF" width="725" cellpadding="0" cellspacing="0"&gt; &lt;tr id="toptr"&gt; &lt;td&gt;&lt;%= sortable "name", "Navn" %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;% @konkurrancer.each do |vind| %&gt; &lt;tr class="thumbnail-item" onclick="window.open('&lt;%= vind.tracking %&gt;')" onmouseout="this.style.background='white';" onmouseover="this.style.background='#99ff33';this.style.cursor='pointer'"&gt; &lt;td width="280px" style="padding-left: 5px;"&gt;&lt;%= truncate(vind.name.force_encoding("UTF-8"), :length =&gt; 45) %&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="container"&gt;&lt;%= render :partial =&gt; "rating", :remote =&gt; true, :locals =&gt; { :vind =&gt; vind } %&gt;&lt;/div&gt;&lt;/td&gt; &lt;/div&gt; &lt;/tr&gt; &lt;% end %&gt; &lt;/table&gt; &lt;div id="pagenavi"&gt; &lt;%= hidden_field_tag :direction, params[:direction] %&gt; &lt;%= hidden_field_tag :sort, params[:sort] %&gt; &lt;/div&gt; </code></pre> <p>My ratings partial:</p> <pre><code>&lt;%= form_tag url_for(controller: 'konkurrancers', action: 'rate', id: "#{vind.id}"), remote: true %&gt; &lt;%= f.text_field :ratings, :size =&gt; 1, :min =&gt; 0, :max =&gt; 5, :step =&gt; 1 %&gt; &lt;div class="rateit" data-rateit-backingfld="#konkurrancer_ratings" data-rateit-resetable="true"&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>My rate.js:</p> <pre><code>$('#&lt;%= @container %&gt;').html('&lt;%= escape_javascript(render(partial: 'rating', locals: { konkurrancer: @konkurrancer })) %&gt;'); </code></pre> <p>My konkurrancers controller:</p> <pre><code> def rate @konkurrancer = Konkurrancer.find(params[:id]) @container = "Konkurrancer"+@Konkurrancer.id.to_s @theme.rating_score += params[:rating].to_i @theme.ratings += 1 @theme.save respond_to do |format| format.js end end end </code></pre>
    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.
 

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