Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
astrsky opened this issue Feb 27, 2018 · 1 comment

Comments

@astrsky
Copy link

astrsky commented Feb 27, 2018

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
@fazaamajdeddine
Copy link

any help please ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants