richguk / jquery-star-rating-rails Goto Github PK
View Code? Open in Web Editor NEWUse jQuery star rating from fyneworks with Rails 3.1
License: MIT License
Use jQuery star rating from fyneworks with Rails 3.1
License: MIT License
I'd like to use this potentially, but the documentation doesn't really seem to be there... and I'm pretty terrible at figuring such out from the code alone... any tips to getting started? If I have Users and I have Products, I'd like Users to be able to leave ratings on Products for example...
I created a very simple application to see how it works. The problem I could see is that every time I have to reload a page to display rating stars, if not, the radio buttons are displayed instead.
Here is my versions:
Here is how ratings are declared in the view:
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :experience %><br>
<% User.notation_range.each do |star| %>
<%= f.radio_button :experience, star, {class: "star" } %>
<% end %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
User model:
class User < ActiveRecord::Base
def self.notation_range
(0..5)
end
end
Declarations of query-star_rating js (application.js)
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require jquery-star-rating
//= require_tree .
Declarations of query-star_rating css (application.css):
*= require_self
*= require jquery-star-rating
*= require_tree .
*/
All the stuff was generated by a simple scaffold generator, so there is nothing special.
Any idea ? Thnx.
Hi RichGuk,
As the plugin is using $.browser, there is a bug with jquery 1.9, could you update ?
Can you please improve the Usage area in the Readme file?
I believe for Rails 3.1 by default it uses Coffeescript and SCSS.
For example, if our controller is called Projects:
In projects.js.coffee, add the line
//= require jquery-star-rating
In projects.css.scss, add the line
/*
*= require jquery-star-rating
*/
In our view (e.g. new.html.erb) add the "star" class to your radio buttons:
<%= f.label :rating, "Rating" %>
<%= f.radio_button :rating, "1", :class => "star" %>
<%= f.radio_button :rating, "2", :class => "star" %>
<%= f.radio_button :rating, "3", :class => "star" %>
<%= f.radio_button :rating, "4", :class => "star" %>
<%= f.radio_button :rating, "5", :class => "star" %>
Should jquery.MetaData be included with this gem?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.