ashvin
ashvin

Reputation: 2040

how to do not allow particular user to give rating using ratyrate gem

I am using ratyrate gem for rating in my rails application. there is user who can purchase or sell his books. but User can not rate his own book(Uploaded by same user).

and when i reload page then only it show rating. how to show rating on button click without reload.....

User model.

class User < ActiveRecord::Base
  ratyrate_rater
end

Book model.

class Book < ActiveRecord::Base
  ratyrate_rateable "price_for_sale"
end

books/index.html.erb.

<div class="row">
  <div class="col-md-8">
      <table class="cls_book_details" cellspacing="0" cellspacing="0">  
        <tr>
            <%@count =1 %>
            <% @books.each do |book| %>
                <td id="book_details" style="text align:left;"><%=link_to(image_tag(book.book_photos.first.photo.url(:thumb), :title => 'Click for edit'), edit_book_path(book.id))%><br>
                    Book Title : <%= book.book_name %><br>
                    Author : <%= book.book_auther %><br>
                    <%= rating_for book, "price_for_sale", :enable_half => true %><br/><br>
                    </td>
                <%@count += 1 %>
                <%if @count == 4%>
                    <% @count =1 %>
                    </tr>
                    <tr>
                <%end %>
            <% end %>
        </tr>
    </table>
</div>

Upvotes: 0

Views: 592

Answers (1)

SSR
SSR

Reputation: 6438

For that you should check your logged in user with your book user. If they are same then prevent him by doing so

if obj.user.id == current_user.id
  flash[:alert] = "You can not rate your own book"
else
  obj.rate params[:score].to_f, current_user, params[:dimension]
end

Your second question's answer is use ajax not to reload page.

Full detail over AJAX in rails http://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html

Here is an good example http://code.tutsplus.com/tutorials/using-unobtrusive-javascript-and-ajax-with-rails-3--net-15243

Upvotes: 2

Related Questions