edgarjs / ajaxful-rating

Provides a simple way to add rating functionality to your application.
http://rdoc.info/projects/edgarjs/ajaxful-rating
417 stars 127 forks source link

cant submit Submit Votes #24

Closed rodrigoaronas closed 14 years ago

rodrigoaronas commented 14 years ago

Hello, I've just installed and set up this nice plugin. In my view I have <%= ratings_for @recipe, @logged_in, :static,:remote_options => {:url => 'recipes/rate/' + @recipe.id.to_s} %> Person is the rater, Recipe is to be rated. Its displaying a row of stars (like 40) and I cant click on any of them to submit my vote. Can this be used w/out any dimensions? just rate the enitre model? Thanks!

edgarjs commented 14 years ago

Hello,

You're passing both options @logged_in (which I guess is the current user) and :static. You need to pass ONLY one of them, @logged_in would be the user which will rate the recipe. The :static option is a "placeholder" to tell the helper to display non-clickable stars, this is for example when you want to show only the rating average of a recipe.

And, if you want to take @logged_in as the user to calculate the displayed stars, BUT don't want him to be able to click the stars, you can pass the option :force_static => true.

Also, I see your url is the default one, in this case you don't need to pass it, just add it to your routes file like said in the readme.

As for the long row of stars, you may be missing the css and javascript includes. Be sure to put these lines within your head tag of your layout:


<%= javascript_include_tag :defaults %>
<%= ajaxful_rating_style %>

Please be sure to fully read the readme file so you can see how it's used. And you can see the wiki page as well. Or the demo code if you want to see actual implementation.

rodrigoaronas commented 14 years ago

Hello, Ive set up my route, put the defaults and the style, and still cant make the start votable and have the full row of start non clickeable. I have on the view: <%= ratings_for @recipe,@logged_in %> controller: def rate @recipe = Recipe.find(params[:id]) @recipe.rate(params[:stars], @logged_in, params[:dimension]) render :update do |page| page.replace_html @recipe.wrapper_dom_id(params), ratings_for(@recipe, params.merge(:wrap => false)) page.visual_effect :highlight, @recipe.wrapper_dom_id(params) end end routes.rb map.resources :recipes, :member => {:rate => :post}

Is tehre anything wrong?

Thanks!

edgarjs commented 14 years ago

Could you paste the generated HTML from the helper?

rodrigoaronas commented 14 years ago

Yes, sure! I've managed to display just 5 stars, not all the row, but still cannot submit votes. heres the HTML Thats it. Thanks1

rodrigoaronas commented 14 years ago

I cant make it work. Please can you help me? I have a Person model which i dont know if its an authenticated model... i need to login, etc, but its just showing the starts with no Ajax on it to vote (the example above ive created 2 votes on the DB to see if they were shown)

edgarjs commented 14 years ago

Sorry, how come you don't know if Person is an authenticated model?

What I mean is that you need to pass an instance of the current logged in user to be able to click the stars. The plugin won't allow a 'guest' to click a star, since it doesn't know anything about the 'guest', it must be a recognized (logged in) user to save the record properly.

Please see the code of the demo application to have a general idea of how to use it.

rhnorment commented 14 years ago

edgar --

i'm no rails expert, but i'm having the same problem rodrigo is. you and i exchanged emails on this about a month ago.

i notice your sample code utilizes the restful_authentication plugin. i'm using a derivative of that which is found in a book on rails social networking. i wonder if rodrigo is using the same authentication method found in that book.

again, i am no rails expert -- and i'm trying to recall the intricacies of the restful_authentication plugin from memory (so I could be wrong).....

but i recall restful_authentication having a session model in addition to a session controller. the authentication method i am using does not have a session model, but it does authenticate with the user model. ergo, i'm wondering (aloud here) if some session parameters (that do not exist for me) need to exist in order for this gem to work properly.

thoughts?

edgarjs commented 14 years ago

So then how do you know if a user is logged in or not? There should be something in the plugin to handle the state of the user. You could use any of the techniques provided for the plugin to create a custom method called current_user and validate if the user is already logged in.

If you remember the name of the plugin that'd be helpful.

rhnorment commented 14 years ago

Here is the authentication code i'm using. it's in the LIB folder:

module LoginSystem

protected

def is_logged_in? @logged_in_user = User.find(session[:user]) if session[:user] end

def logged_in_user return @logged_in_user if is_logged_in? end

def logged_in_user=(user) if !user.nil? session[:user] = user.id @logged_in_user = user end end

def check_role(role) unless is_logged_in? && logged_in_user.has_role?(role) flash[:error] = "You do not have permission to do that." redirect_to login_url end end

def check_administrator_role check_role('administrator') end

def login_required unless is_logged_in? flash[:error] = "You must be logged in to do that." redirect_to login_url end end

def self.included(base) base.send :helper_method, :is_logged_in?, :logged_in_user end

end

edgarjs commented 14 years ago

Try adding an alias to: alias current_user logged_in_user

rhnorment commented 14 years ago

I just noticed your alias post. Which method would I put this in?

edgarjs commented 13 years ago

Just below your logged_in_user. Or anywhere after the method is defined.