実現したいこと
ratyrateのgemを使用し実装をしてます。
星の評価を自分で動かせるようにしたいのですが、現状下記画像のようになってしまいます。
対象箇所の記入
showページ
<p id="notice"><%= notice %></p> <p> <strong>Name:</strong> <%= @car.name %> </p> <!-- default --> <p> Speed : <%= rating_for @car, 'speed' %> </p> <!-- disableafterrate --> <!-- <p> Speed : <%= rating_for @car, 'speed', disable_after_rate: false %> </p> --> <!-- star --> <!-- <p> Speed : <%= rating_for @car, 'speed', star: 10 %> </p> --> <!-- half-star --> <!-- <p> Speed : <%= rating_for @car, 'speed', disable_after_rate: false, tar: 5, enable_half: true %> </p> --><%= link_to 'Edit', edit_car_path(@car) %> |
<%= link_to 'Back', cars_path %>
アプリケーション。js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery.raty
//= require ratyrate
//= require rails-ujs
//= require activestorage
//= require turbolinks
//= require_tree .
rating テーブル
class CreateRatingCaches < ActiveRecord::Migration[5.2]
def self.up
create_table :rating_caches do |t|
t.belongs_to :cacheable, :polymorphic => true
t.float :avg, :null => false
t.integer :qty, :null => false
t.string :dimension
t.timestamps
end
add_index :rating_caches, [:cacheable_id, :cacheable_type] end def self.down drop_table :rating_caches end
end
rates テーブル
class CreateRates < ActiveRecord::Migration[5.2]
def self.up
create_table :rates do |t|
t.belongs_to :rater
t.belongs_to :rateable, :polymorphic => true
t.float :stars, :null => false
t.string :dimension
t.timestamps
end
add_index :rates, :rater_id add_index :rates, [:rateable_id, :rateable_type] end def self.down drop_table :rates end
end
averageテーブル
class CreateAverageCaches < ActiveRecord::Migration[5.2]
def self.up
create_table :average_caches do |t|
t.belongs_to :rater
t.belongs_to :rateable, :polymorphic => true
t.float :avg, :null => false
t.timestamps
end
end
def self.down
drop_table :average_caches
end
end
overallテーブル
class CreateOverallAverages < ActiveRecord::Migration[5.2]
def self.up
create_table :overall_averages do |t|
t.belongs_to :rateable, :polymorphic => true
t.float :overall_avg, :null => false
t.timestamps
end
end
def self.down
drop_table :overall_averages
end
end
carモデル
class Car < ApplicationRecord
ratyrate_rateable "speed"
end
よろしくお願い致します。
あなたの回答
tips
プレビュー