Closed ghost closed 13 years ago
Sorry, I'll try that again...
Average: <div class="ajaxful-rating-wrapper" id="ajaxful_rating_no-small_place_2"><ul class="ajaxful-rating"><li class="show-value" style="width: 50.0%">Global rating average: 2.5 out of 5</li><li><span class="stars-1" title="Global rating average: 2.5 out of 5">2.5</span></li><li><span class="stars-2" title="Global rating average: 2.5 out of 5">2.5</span></li><li><span class="stars-3" title="Global rating average: 2.5 out of 5">2.5</span></li><li><span class="stars-4" title="Global rating average: 2.5 out of 5">2.5</span></li><li><span class="stars-5" title="Global rating average: 2.5 out of 5">2.5</span></li></ul></div></br>
Your Rating: <div class="ajaxful-rating-wrapper" id="ajaxful_rating_no-small_place_2"><ul class="ajaxful-rating"><li class="show-value" style="width: 20.0%">Your rating: 1 out of 5</li><li><a href="/places/2/rate?dimension=&show_user_rating=true&small=false&stars=1" class="stars-1" data-method="post" data-remote="true" rel="nofollow" title="Rate 1 out of 5">1</a></li><li><a href="/places/2/rate?dimension=&show_user_rating=true&small=false&stars=2" class="stars-2" data-method="post" data-remote="true" rel="nofollow" title="Rate 2 out of 5">2</a></li><li><a href="/places/2/rate?dimension=&show_user_rating=true&small=false&stars=3" class="stars-3" data-method="post" data-remote="true" rel="nofollow" title="Rate 3 out of 5">3</a></li><li><a href="/places/2/rate?dimension=&show_user_rating=true&small=false&stars=4" class="stars-4" data-method="post" data-remote="true" rel="nofollow" title="Rate 4 out of 5">4</a></li><li><a href="/places/2/rate?dimension=&show_user_rating=true&small=false&stars=5" class="stars-5" data-method="post" data-remote="true" rel="nofollow" title="Rate 5 out of 5">5</a></li></ul></div>
Do you update the view in your controller?
Hi, thanks for the prompt response - I've got the rate action in my place controller (and routes) taken directly from the wiki, I can post it when I get home.
Sorry about the delay. In my places controllers:
def rate
@place = Place.find(params[:id])
@user = User.find(current_user.id)
@place.rate(params[:stars], @user, params[:dimension])
render :update do |page|
page.replace_html @place.wrapper_dom_id(params), ratings_for(@place, params.merge(:wrap => false))
page.visual_effect :highlight, @place.wrapper_dom_id(params)
end
end
In my routes.rb file:
resources :places do
resources :comments
member do
post :rate
end
end
The stars are fine, and they highlight on mouse-over, but it seems the ajax bit isn't quite working...thanks for your help!
Humm, try logging the value of @place.wrapper_dom_id(params)
and check if it's exactly the same as in your markup. There was a problem with this method on previous versions, where it wasn't generating the correct dom id.
Using <%= debug @place.wrapper_dom_id(params) %> gives --- ajaxful_rating_place_2
I've just noticed a no method error after clicking on a star though:
NoMethodError (undefined method `encoding' for []:Array):
app/controllers/places_controller.rb:37:in `block in rate'
app/controllers/places_controller.rb:36:in `rate'
Line 36 is render :update..., and 37 is page.replace_html...
Can you paste the full trace please?
After clicking, I get:
Started POST "/places/2/rate? dimension=&show_user_rating=true&small=false&stars=4" for 127.0.0.1 at 2010-06-22 16:11:59
[1m[36mUser Load (0.3ms)[0m [1mSELECT "users".* FROM "users" WHERE ("users"."id" = 1) LIMIT 1[0m
Processing by PlacesController#rate as JS
Parameters: {"dimension"=>"", "show_user_rating"=>"true", "small"=>"false", "stars"=>"4", "id"=>"2"}
[1m[35mPlace Load (0.3ms)[0m SELECT "places".* FROM "places" WHERE ("places"."id" = 2) LIMIT 1 [1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE ("users"."id" = 1) LIMIT 1[0m [1m[35mRate Load (0.3ms)[0m SELECT "rates".* FROM "rates" WHERE ("rates".rateable_id = 2 AND "rates".rateable_type = 'Place' AND ("rates"."dimension" IS NULL)) AND ("rates"."rater_id" = 1) LIMIT 1 [1m[36mCACHE (0.0ms)[0m [1mSELECT "rates".* FROM "rates" WHERE ("rates".rateable_id = 2 AND "rates".rateable_type = 'Place' AND ("rates"."dimension" IS NULL)) AND ("rates"."rater_id" = 1) LIMIT 1[0m [1m[35mSQL (0.4ms)[0m UPDATE "rates" SET "stars" = 4, "updated_at" = '2010-06-22 15:11:59.645047' WHERE ("rates"."id" = 1) [1m[36mSQL (0.3ms)[0m [1mSELECT SUM("rates"."stars") AS sum_id FROM "rates" WHERE ("rates".rateable_id = 2 AND "rates".rateable_type = 'Place' AND ("rates"."dimension" IS NULL))[0m [1m[35mSQL (0.2ms)[0m SELECT COUNT(*) AS count_id FROM "rates" WHERE ("rates".rateable_id = 2 AND "rates".rateable_type = 'Place' AND ("rates"."dimension" IS NULL)) [1m[36mSQL (0.4ms)[0m [1mUPDATE "places" SET "rating_average" = 4.0, "updated_at" = '2010-06-22 15:11:59.653100' WHERE ("places"."id" = 2)[0m
NoMethodError (undefined method `to_hash' for "4":String):
app/controllers/places_controller.rb:37:in `block in rate'
app/controllers/places_controller.rb:36:in `rate'
Rendered /Users/soniabracegirdle/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.4ms)
[1m[35mSQL (1.0ms)[0m SELECT name FROM sqlite_master WHERE type = 'table' AND NOT name = 'sqlite_sequence' [1m[36mSQL (0.3ms)[0m [1m SELECT name FROM sqlite_master WHERE type = 'table' AND NOT name = 'sqlite_sequence' [0m [1m[35mSQL (0.4ms)[0m SELECT name FROM sqlite_master WHERE type = 'table' AND NOT name = 'sqlite_sequence' [1m[36mSQL (0.4ms)[0m [1m SELECT name FROM sqlite_master WHERE type = 'table' AND NOT name = 'sqlite_sequence' [0m [1m[35mSQL (0.4ms)[0m SELECT name FROM sqlite_master WHERE type = 'table' AND NOT name = 'sqlite_sequence' [1m[36mSQL (0.4ms)[0m [1m SELECT name FROM sqlite_master WHERE type = 'table' AND NOT name = 'sqlite_sequence' [0m [1m[35mSQL (0.3ms)[0m SELECT name FROM sqlite_master WHERE type = 'table' AND NOT name = 'sqlite_sequence' [1m[36mSQL (0.4ms)[0m [1m SELECT name FROM sqlite_master WHERE type = 'table' AND NOT name = 'sqlite_sequence' [0m Rendered /Users/soniabracegirdle/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (242.8ms) Rendered /Users/soniabracegirdle/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (317.5ms)
There's also a google map on the page, which displays the location of the places...don't know if that's related!
Just noticed the no method error has changed this time round...on looking at the log it seems it's almost always 'encoding' that is undefined.
Does it throw anything else after the app/controllers/places_controller.rb:36:in rate
? I need to see the full trace, inside the rate
method. I don't know why it's trying to do a to_hash to the 4...
I've pasted my entire places controller up: http://pastie.org/1016826, along with the log (from loading places#show, then updating a rating for a signed-in user): http://pastie.org/1016830. Is there anything else I can do to debug? I'm quite new to RoR, sorry for not being more helpful!
I just noticed you're using ruby 1.9.1. Is it possible to try it with 1.8.7? It seems like it has something there.
thanks for all the help, unfortunately I've just managed to overwrite my entire app - I'm overseas at the moment so a bit stuck for now! When I get it back up and running again I'll have a go with 1.8.7...
Just to confirm, the code above works fine running rails 3 beta 4 with 1.8.7. I had some issues using jQuery as well, so have switched back to prototype. Cheers!
Ok, that's great. Thanks for the feedback. I'll look forward to support more ruby versions in the future.
i run also in this 'encoding' error. i fixed it with calling the rating_for helper from a partial instead direct calling inside my controller:
page.replace_html :info_ratings_overall, :partial => 'static' page.replace_html @game.wrapper_dom_id(params), :partial => 'interactive'
looks very strange... (macosx, ruby 1.9.2, rails3-beta4, ajaxful_rating 2.2.8.1)
I get this same problem and am trying to follow the fixes for it but cannot - using ruby 1.8.7 with rails 2.3.8... it is saving the rating but not updating the page without a refresh
I'm getting a similar problem, it gives me the following error: RJS error:
TypeError: Element.update is not a function
Same as Marcoam I am getting the RJS error and require refresh to show the new rating. Any help?
Error Popup 1:
RJS error:
TypeError: Object function Element() { [native code] } has no method 'update'
Error Popup 2:
Element.update("ajaxful_rating_no-small_item_3", "<ul class=\"ajaxful-rating\"><li class=\"show-value\" style=\"width: 60.0%\">Global rating average: 3.0 out of 5</li><li><a href=\"/items/canon-eos-450d/rate?dimension=&show_user_rating=false&small=false&stars=1\" class=\"stars-1\" data-method=\"post\" data-remote=\"true\" rel=\"nofollow\" title=\"Rate 1 out of 5\">1</a></li><li><a href=\"/items/canon-eos-450d/rate?dimension=&show_user_rating=false&small=false&stars=2\" class=\"stars-2\" data-method=\"post\" data-remote=\"true\" rel=\"nofollow\" title=\"Rate 2 out of 5\">2</a></li><li><a href=\"/items/canon-eos-450d/rate?dimension=&show_user_rating=false&small=false&stars=3\" class=\"stars-3\" data-method=\"post\" data-remote=\"true\" rel=\"nofollow\" title=\"Rate 3 out of 5\">3</a></li><li><a href=\"/items/canon-eos-450d/rate?dimension=&show_user_rating=false&small=false&stars=4\" class=\"stars-4\" data-method=\"post\" data-remote=\"true\" rel=\"nofollow\" title=\"Rate 4 out of 5\">4</a></li><li><a href=\"/items/canon-eos-450d/rate?dimension=&show_user_rating=false&small=false&stars=5\" class=\"stars-5\" data-method=\"post\" data-remote=\"true\" rel=\"nofollow\" title=\"Rate 5 out of 5\">5</a></li></ul>");
new Effect.Highlight("ajaxful_rating_no-small_item_3",{});
Hey jhender, are you using rails 3?
yes i am
the correct version for rails 3 is beta.3 However as its name says it's still in beta and not fully supported, but you error is related to the new rails 3 API, not a gem's error. In rails 3 there's no update in the controller for ajax anymore.
Hi,
At present in my app the rating is not being updated after clicking on the stars, although the value is being recorded as after a page refresh the new rating appears. In my view:
Which generates:
Your Rating:
I'm using Ruby 1.9.1 and Rails 3.0.0beta3 with jQuery, any help would be much appreciated! Awesome plugin btw...