Forum: Ruby on Rails Star Rating Component?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
74592905ef38cd087e5b73c0955aaa18?d=identicon&s=25 Martin Smith (Guest)
on 2006-03-07 14:42
Hi,

I'm looking for a star rating component for RoR, a bit like Votio
(http://redalt.com/downloads/ - find the votio heading) or the star
rating used on Amazon.

I don't really need the AJAX capabilities, just the ability to bind the
results to a hidden drop down, or radio inputs.

Multiple raters per page is also an issue.

Any recomendations?
00973881979aa0a660ffbbb2f7a907fb?d=identicon&s=25 Peter De Berdt (Guest)
on 2006-03-07 15:01
(Received via mailing list)
On 07 Mar 2006, at 14:42, Martin Smith wrote:

> Multiple raters per page is also an issue.
>
> Any recommendations?

If you have the Rails Recipes book, you could read up on the
JavaScript helper section and implement the open source version from
the Yahoo UI Library and hide it behind one simple ruby command.

Best regards

Peter De Berdt
E98de78bb42013c488fe8aa9d77d2cb1?d=identicon&s=25 Steve Odom (Guest)
on 2006-03-07 15:28
(Received via mailing list)
Hi Martin,

I've got a flash-version I built and included via flash-javascript
integration kit. Works great. Let me know if you want it and I'll send
it
over.

Steve
74592905ef38cd087e5b73c0955aaa18?d=identicon&s=25 Martin Smith (Guest)
on 2006-03-07 16:01
Steve Odom wrote:
> Hi Martin,
>
> I've got a flash-version I built and included via flash-javascript
> integration kit. Works great. Let me know if you want it and I'll send
> it
> over.
>
> Steve

Thanks, for that.  I would really prefer to keep it just javascript
though.  I assume that for your version you need flash installed.
74592905ef38cd087e5b73c0955aaa18?d=identicon&s=25 Martin Smith (Guest)
on 2006-03-07 16:03
Peter De Berdt wrote:

>
> If you have the Rails Recipes book, you could read up on the
> JavaScript helper section and implement the open source version from
> the Yahoo UI Library and hide it behind one simple ruby command.

Sadly I don't.  I have looked at the Yahoo UI Library, but could only
find the Star Rater in the patterns section, not in the download.

Martin
00973881979aa0a660ffbbb2f7a907fb?d=identicon&s=25 Peter De Berdt (Guest)
on 2006-03-07 18:07
(Received via mailing list)
On 07 Mar 2006, at 16:03, Martin Smith wrote:

> Peter De Berdt wrote:
>
>>
>> If you have the Rails Recipes book, you could read up on the
>> JavaScript helper section and implement the open source version from
>> the Yahoo UI Library and hide it behind one simple ruby command.
>
> Sadly I don't.  I have looked at the Yahoo UI Library, but could only
> find the Star Rater in the patterns section, not in the download.

Well, the nice thing about javascript is that you can extract it from
a page:

http://us.js2.yimg.com/us.yimg.com/lib/ls/js/
yg_multirate_200602281800.js

They then use the following code to show the rating system:
	<script>
	if (document.getElementById)
	 {
		// Support for Class A.
		rating = new yg_Ratings("rating", "", 0, "star");
	 }
	 else
	 {
		// Support for poor DOM (low grade).
		document.write('<div>');
		document.write('1 Star<input type="radio" name="rating" value="" />');
		document.write('<input type="radio" name="rating1" value="" />');
		document.write('<input type="radio" name="rating2" value="" />');
		document.write('<input type="radio" name="rating3" value="" />');
		document.write('<input type="radio" name="rating4" value="" />5
Stars');
		document.write('</div>');
		//document.write('<input class="save" type="submit" name="submit"
value="Save" class="ylsfbtn" />');
	 }
         </script>

Just go to http://local.yahoo.com/, search for "Restaurants" in
Location "New York", click on a restaurant for the detail (which has
the widget) and then look at the source.


Best regards

Peter De Berdt
Ff82af3238a57fbd1212832ec1a19f28?d=identicon&s=25 Dylan Stamat (Guest)
on 2006-03-07 18:59
(Received via mailing list)
I think the CSS approach to this is the best.  I implemented the
following
approach, which is very popular:
http://komodomedia.com/blog/index.php/2006/01/09/c...

The code I used below enabled the "ajaxy" part of this... so when you
click
on a star, it automatically saves your pick... much like the Netflix
star
system.

===========================
<ul class='star-rating'>
          <div id='super'>
            <% if @review %>
              <li class='current-rating'
                  style='width: <%= @review.rating * 30 %>px;'>&nbsp;
</li>
            <% end %>
        </div>

            <% for i in 1..5 %>
            <li>
                <%= link_to_remote i, {:update => 'super',
                                       :url   => {:action    =>
'rate_cause',
                                                  :cause_id  =>
@cause.id,
                                                  :user_id   =>
@user.id,
                                                  :rating    => i}},
                                      {:class  =>
num2english(i)+"-stars"}
%>
            </li>
            <% end %>
</ul>
===========================

It works beautifully !
Let me know if you have any questions.
47093444301bbde90d0aef5fa5c3ac86?d=identicon&s=25 John Hornbeck (Guest)
on 2006-03-07 23:19
(Received via mailing list)
Dylan,  Can we see the controller code you are using?

John
Ff82af3238a57fbd1212832ec1a19f28?d=identicon&s=25 Dylan Stamat (Guest)
on 2006-03-08 17:02
(Received via mailing list)
Sure !  Here you go... but please excuse the mess :)


controller
===============
def rate_cause
id, id, rating = params[:id], params[:id], params[:rating]
@review = Review.find(:first, :conditions => ["id = ? and id = ?", id,
id])
if @review
  @review.update_attribute("rating", rating)
else
  @review = Review.create(:id => id, :id => id, :rating => rating)
end
render(:layout => false)
end
===============


rate_cause.rhtml
===============
<% if @review %>
  <li class='current-rating' style='width: <%= @review.rating * 30
%>px;'>&nbsp;</li>
<% end %>
===============
47093444301bbde90d0aef5fa5c3ac86?d=identicon&s=25 John Hornbeck (Guest)
on 2006-07-17 21:04
(Received via mailing list)
Dylan,

what does your Review table look like?(database schema)

John
Ba15b74b5b6e757a0a69a4ade447c564?d=identicon&s=25 Nagesh Sangana (nagesh)
on 2007-08-16 08:57
hi
can uany one give me the entire coding for starrating.
plz............
thanks
This topic is locked and can not be replied to.