NoMethodError undefined method のエラーが出る
初めての質問です。
Ruby on railsで勉強をさせて頂いているのですが
rails sを行いページを見ようとすると下記のようなエラがー出てしまいます。
解決法をお教え頂ければ幸いです。
- ruby v2.2.2
- rails v4.2.5.1
エラー名
NoMethodError in ProjectController#show
undefined method `users' for #<Project:0x007f9ef37c73a8>
app/controllers/project.controller.rb
class ProjectController < ApplicationController
before_action :authenticate_user!, only: [:list]
def index
@projects = Project.all
end
def show
@project = Project.find(params[:id])
@tasks = @project.tasks.order(:tag)
@joined = false
if !current_user.nil? && !current_user.projects.nil?
@joined = current_user.projects.include?(@project)
end
@users = @project.users.order('created_at desc').first(10)
end
def list
if !current_user.nil?
@projects = current_user.projects
end
end
end
app/admin/project.rb
ActiveAdmin.register Project do
permit_params :name, :content, :price, :image
show do |t|
attributes_table do
row :name
row :content
row :price
row :image do
project.image? ? image_tag(project.image.url, height: '100') : content_tag(:span, "No photo yet")
end
end
end
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs do
f.input :name
f.input :content
f.input :price
f.input :image, hint: f.project.image? ? image_tag(project.image.url, height: '100') : content_tag(:span, "Upload JPG/PNG/GIF image")
end
f.actions
end
end
app/model/project.rb
class Project < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: [:slugged, :finders]
has_many :tasks
validates :name, presence: true, length: { maximum: 50 }
validates :content, presence: true, length: { maximum: 500 }
validates :price, presence: true, numericality: { only_integer: true }
has_attached_file :image, :styles => { :medium => "680x300>", :thumb => "170x75>" }
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
def shortname
name.length > 25? name[0..25] + "..." : name
end
end
app/project/views/project/show.html.rb