Skip to content
This repository has been archived by the owner on Feb 5, 2021. It is now read-only.

Rails 3.1 #56

Open
jspooner opened this issue Aug 25, 2011 · 18 comments
Open

Rails 3.1 #56

jspooner opened this issue Aug 25, 2011 · 18 comments

Comments

@jspooner
Copy link

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
Copy link
Author

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

@edgarjs
Copy link
Owner

edgarjs commented Aug 25, 2011

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

@jspooner jspooner reopened this Aug 25, 2011
@jspooner
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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.

@edgarjs
Copy link
Owner

edgarjs commented Aug 31, 2011

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 edgarjs closed this as completed Aug 31, 2011
@josephers
Copy link

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

@jspooner
Copy link
Author

@josephers +1

@edgarjs edgarjs reopened this Oct 19, 2011
@jimishjoban
Copy link

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.

@PikachuEXE
Copy link

@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...)

@zben
Copy link

zben commented Feb 4, 2012

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.

@edgarjs
Copy link
Owner

edgarjs commented Feb 4, 2012

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:
#56 (comment)

@mauroc
Copy link

mauroc commented Mar 21, 2012

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!

@katafrakt
Copy link

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

@mauroc
Copy link

mauroc commented Mar 23, 2012

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

@pslaski
Copy link

pslaski commented May 10, 2012

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?

@greendog99
Copy link

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.

@pslaski
Copy link

pslaski commented May 13, 2012

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)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants