ratyrate icon indicating copy to clipboard operation
ratyrate copied to clipboard

undefined method `overall_avg' for #<Recipe::ActiveRecord_Relation:0x007f5154d4ea20>

Open astrsky opened this issue 6 years ago • 1 comments

Pls help. After installing ratyrate and i've done like in Instruction at GItHub I got this undefined method `overall_avg' for #Recipe::ActiveRecord_Relation:0x007f5154d4ea20

my user.rb

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  ratyrate_rater

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
   has_many :recipe
  

end
my recipe.rb

class Recipe < ApplicationRecord
  belongs_to :user

  has_many :ingredients
  has_many :directions
  has_many :comments, as: :commentable
  
  ratyrate_rateable "recipe_rating"
   


  accepts_nested_attributes_for :ingredients,
                                 reject_if: proc { |attributes| attributes['name'].blank? },
                                 allow_destroy: true
  accepts_nested_attributes_for :directions,
                                 reject_if: proc { |attributes| attributes['step'].blank? },
                                 allow_destroy: true

  validates :title, :description, :image, presence: true

  has_attached_file :image, styles: { medium: "400x400#"}
  validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
end

my index.html.haml

- @recipe.each_slice(3) do |recipes|
  .row
    -recipes.each do |recipe|
      .col-md-4
        .recipe
          .image_wrapper
            = link_to recipe do
              =image_tag recipe.image.url(:medium)
          %h2= link_to recipe.title,recipe

  .row
    .small-2.large-2.columns
      = imdb_style_rating_for @recipe, current_user
    %br/
    .small-2.large-4.columns
      - if current_user
        Recipe Ratings: #{rating_for @recipe, "recipe_rating"}

my ricipes_controller

class RecipesController < ApplicationController
  before_action :find_recipe, only: [:show,:edit, :update, :destroy]
  before_action :authenticate_user!, exept: [:index, :show]

  def index
    @recipe = Recipe.all.order("created_at DESC")
    
  end

  def show

  end

  def new
    @recipe = current_user.recipe.build
  end

  def create
    @recipe = current_user.recipe.build(recipe_params)

    if @recipe.save
      redirect_to @recipe, notice: "Successfully created new recipe"

    else
      render 'new'
    end
  end

  def edit
  end

  

  def update
    if @recipe.update(recipe_params)
      redirect_to @recipe
    else
      render 'edit'
    end
  end

  def destroy
    @recipe.destroy
    redirect_to root_path, notice: "Successfully deleted recipe"
  end

  private

  def recipe_params
    params.require(:recipe).permit(:title, :description, :image, ingredients_attributes: [:id, :name, :_destroy], directions_attributes: [:id, :step, :_destroy])
  end

  def find_recipe
    @recipe = Recipe.find(params[:id])
  end
end

astrsky avatar Feb 27 '18 12:02 astrsky

any help please ??

fazaamajdeddine avatar Aug 27 '21 12:08 fazaamajdeddine