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

Rating possible but no page update #41

Open
helmerj opened this issue Aug 24, 2010 · 6 comments
Open

Rating possible but no page update #41

helmerj opened this issue Aug 24, 2010 · 6 comments

Comments

@helmerj
Copy link

helmerj commented Aug 24, 2010

Hi,

I have implemented the ajaxful-rating and I am able to rate my model. BUT I don’t get any page update. in order to see the applied rating I have to reload the page.

Admittedly, I am using the ajaxful-rating gem under rather complicated circumstances:

  1. I rate users, so the the model that is rating is ratable at the same time
  2. I use the rating feature in an admin name space
  3. the admin name space uses active scaffold for the controller and view logic.
  4. rails 2.3.8 and ruby 1.8.7, gem version is 2.2.8.1

I am able to display the global rating and under that the rating of that particular user using the following code in my view:

  
Avarage Rating:
<%= ratings_for @record, :static, :remote_options => {:url => ate_admin_user_path(@record)} %>
Your Rating:
<%= ratings_for @record, :show_user_rating => true, :remote_options => {:url => rate_admin_user_path(@record)} %>

I do get the hover effect when mousing over the stars due to including <%= ajaxful_rating_style %> in my layout file.
When clicking a star the rating is kind of indicated by keeping number of rated stars in the hover state (red/orange). The rating does take place due to my controller functions:

def rate
@record = User.find(params[:id])
@record.rate(params[:stars], current_user, params[:dimension])
render :update do |page|
  page.replace_html @record.wrapper_dom_id(params), ratings_for(@record, params.merge(:wrap => false))
  page.visual_effect :highlight, @record.wrapper_dom_id(params)
end
end

The rating is applied and the average is calculated which can be seen upon reloading the page. But the ajax part of updating the star rating upon click does not happen. Instead I do get the following error in the logs:

  NameError (Constant AjaxfulRating::MissingRateRoute from   ajaxful_rating/missing_rate_route.rb not found
  Constant MissingRateRoute from missing_rate_route.rb not found):
    desert (0.5.1) lib/desert/rails/dependencies.rb:56:in `look_for_constant_in_parent_module'
    desert (0.5.1) lib/desert/rails/dependencies.rb:13:in `load_missing_constant'
    /home/helmerj/.rvm/gems/ree-1.8.7-2010.02/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
    /home/helmerj/.rvm/gems/ree-1.8.7-2010.02/gems/ajaxful_rating-2.2.8.1/lib/axr/stars_builder.rb:52:in `apply_stars_builder_options!'
    /home/helmerj/.rvm/gems/ree-1.8.7-2010.02/gems/ajaxful_rating-2.2.8.1/lib/axr/stars_builder.rb:10:in `initialize'
    /home/helmerj/.rvm/gems/ree-1.8.7-2010.02/gems/ajaxful_rating-2.2.8.1/lib/axr/helpers.rb:82:in `new'
    /home/helmerj/.rvm/gems/ree-1.8.7-2010.02/gems/ajaxful_rating-2.2.8.1/lib/axr/helpers.rb:82:in `ratings_for'
    app/controllers/admin/users_controller.rb:125:in `rate'
    app/controllers/admin/users_controller.rb:124:in `rate'
    haml (3.0.15) lib/sass/plugin/rack.rb:41:in `call'

    Rendered rescues/_trace (71.6ms)
    Rendered rescues/_request_and_response (0.5ms)
    Rendering rescues/layout (internal_server_error)

My routes for this rating looks like this:

  map.namespace :admin do |admin|
    admin.resources :users, :member => {:rate => :post}, :active_scaffold => true
  end

I am so close, any help on this would be greatly appreciated.

Cheers J.

@helmerj
Copy link
Author

helmerj commented Aug 24, 2010

Using firebug I was able to get a more detailed error on the issue:

http://gist.github.com/547433

@markphelps
Copy link

This is because the code for the ajax callback does not work with nested routes.

My example routes.rb:

map.resources :users do |user|
user.resource :portfolio do |portfolio|
portfolio.resources :images, :member => {:rate => :post}
end
end

I believe the problem lies in lines 47-48 of stars_builder.rb:

rateable_name = ActionController::RecordIdentifier.singular_class_name(rateable)
url = "rate_#{rateable_name}_path"

This assumes that your route is not nested. So url = "rate_image_path" instead of url = "rate_user_portfolio_image_path" (which is what it should be). I patched this by hardcoding the url, but I know this is not the best solution. Any thoughts on how to fix this to work with nested routes?

@hk6500
Copy link

hk6500 commented May 2, 2012

Same problem here. Any updates on this? Or a good workaround?

@crowdvn
Copy link

crowdvn commented Jun 12, 2012

@Joseph-N
Copy link

Thanks @crowdvn...it worked perfectly!!

@anduong
Copy link

anduong commented Dec 27, 2013

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

No branches or pull requests

6 participants