ajaxful-rating icon indicating copy to clipboard operation
ajaxful-rating copied to clipboard

Rails 3.1

Open jspooner opened this issue 12 years ago • 18 comments

Anyone tried to use this with rails 3.1? I think the ajax helpers have been removed so none of the javascript works. I'd be happy to fork and update if your not working on that.

jspooner avatar Aug 25 '11 04:08 jspooner

Sorry I was wrong about this. I think there is a styling error so the links are not displayed

jspooner avatar Aug 25 '11 04:08 jspooner

There is a branch that was started for rails 3.x It works fine on rails 3.0.x but haven't tried on 3.1. The branch is rails3

edgarjs avatar Aug 25 '11 14:08 edgarjs

RJS has been extracted from 3.1 and placed in the prototype-rails gem.

http://weblog.rubyonrails.org/2011/4/21/jquery-new-default

jspooner avatar Aug 25 '11 14:08 jspooner

Here is how I integrated with my 3.1 rc5.

your controller

  # POST
  def rate
    @location = Location.find(params[:id])
    respond_to do |format|
      if @location.rate(params[:stars], current_user, params[:dimension])
        format.js { render :partial => "rating" }
      else
        format.js { render :partial => "rating" }
      end
    end
  end

_rating.html.erb

<%= ratings_for @location, current_user %>

app.js

I'm using jquery-ujs to handle the response. This lib is included with the 'jquery-rails'gem. https://github.com/rails/jquery-ujs

$('a').live('ajax:complete', function(xhr, status) {
  $(".ajaxful-rating-wrapper").replaceWith(status.responseText)
});

ajaxful_ratings.css

Not sure if this is by design or not but I had to set a width on the wrapper so only 5 stars were displayed. It showed all by default.

#sidebar .ajaxful-rating-wrapper {width:125px;}

show.html.erb

<%= render "rating" %>

jspooner avatar Aug 25 '11 16:08 jspooner

Also with 3.1 you don't need to copy the assets into the public directory.

Ryan did a nice demo explaining how to use the different asset directories. http://railscasts.com/episodes/279-understanding-the-asset-pipeline

I could probably find the time to make a 3.1 branch if you want.

jspooner avatar Aug 25 '11 18:08 jspooner

The only rjs helper that I'm "using" is in the README.md file for demonstration only of how you'd like to use it. But that's not dependent of the gem, you can use any js method to update the wrapper. The gem itself doesn't use any rjs helper.

edgarjs avatar Aug 31 '11 15:08 edgarjs

This was incredibly useful for me. Can we leave this open or move this to the documentation?

josephers avatar Oct 17 '11 20:10 josephers

@josephers +1

jspooner avatar Oct 18 '11 15:10 jspooner

Thanks a lot jspooner for putting up that code snipet.

For others, If you are allowing users to rate on multiple dimension, then you must replace the correct wrapper. I did something like this:

   $('a').live('ajax:complete', function(xhr, status) {
      $(this).parent().parent().parent().replaceWith(status.responseText)
   });

And my _rating.html.erb looks like this:

  <%= ratings_for @merchant, current_user, :dimension => dimension, :show_user_rating => true %>

And I pass dimension from merchant controller:

respond_to do |format|
  format.js { render :partial => "rating", :locals => {:dimension => params[:dimension]} }
end

Hope that helps someone.

jimishjoban avatar Dec 08 '11 18:12 jimishjoban

@jimishjoban That certainly helps me! I hate js.erb... Is there a cleaner way to do updating like this? (I mean...create,update,delete items...)

PikachuEXE avatar Jan 07 '12 08:01 PikachuEXE

this question might be silly. when you include gem 'ajaxful-rating', how do you specify it to use Rails3 branch? I guess I can go to the gem folder and do git checkout. But if i am deploying on heroku how do i specify it in GemFile? Thanks.

zben avatar Feb 04 '12 17:02 zben

You just need to add the beta version, like:

gem 'ajaxful_rating', "~> 3.0.0.beta8"

edgar.js

On Sat, Feb 4, 2012 at 11:01 AM, Ben Zhang < [email protected]

wrote:

this question might be silly. when you include gem 'ajaxful-rating', how do you specify it to use Rails3 branch? I guess I can go to the gem folder and do git checkout. But if i am deploying on heroku how do i specify it in GemFile? Thanks.


Reply to this email directly or view it on GitHub: https://github.com/edgarjs/ajaxful-rating/issues/56#issuecomment-3811435

edgarjs avatar Feb 04 '12 17:02 edgarjs

I too have had issues after upgrading to Rails 3.1, even after reverting back to prototype. The rating stars render OK on the page, but the controller stops for a no-method error upon calling the ratings_for helper (the rates table is updated correctly in the previous statement). Note that the helper executes correctly when called by the .erb view. I have tried to follow jspooner's solution but have run aground on the java snippet. I guess I don't know where to place the snippet and how to invoke it, being pretty green on javascript. Any help is truly appreciated!

mauroc avatar Mar 21 '12 03:03 mauroc

Have you tried a solution from wiki? It worked for me recently.

katafrakt avatar Mar 21 '12 12:03 katafrakt

I used that solution and it works great. Next time I will remember to check the wiki :-). Thank you katafrakt!

mauroc avatar Mar 23 '12 14:03 mauroc

I tried jspooner and wiki solutions but it not enough. (I use rails 3.1.4 and Devise) When I want to rate my place I get: 'WARNING: Can't verify CSRF token authenticity' and my user session is dump + rating didn't happen. Are anybody use ajaxful_rating with rails 3.1.4 and Devise?

pslaski avatar May 10 '12 12:05 pslaski

I'm using ajaxful_rating with rails 3.1.3 and Devise (working now thanks to the wiki docs), haven't had any CSRF problems. I assume when you "view source" on your page, you see the CSRF meta tag (like this):

<meta content="onlk5iB/F5yATptrFg7iMHwq9iU5tim8+kc0SVmYFY=" name="csrf-token" />

I'm planning to upgrade to Rails 3.2.3 this week and see if anything breaks.

greendog99 avatar May 12 '12 11:05 greendog99

Yes, I have CSRF meta tag but I don't have token in request's parameters (It should be send by default but it doesn't)

pslaski avatar May 13 '12 00:05 pslaski