I receive the following error message when i post a new party: Party model missing required attr_accessor for 'image_file_name' and it points to the code in my parties_controller.rb:
def create
@party = Party.new(party_params)
Im struggling to understand the reason for this error, Here is the other code i'm working with
party.rb
class Party < ActiveRecord::Base
belongs_to :user
has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
validates :description, presence: true
validates :image, presence: true
end
parties_controller.rb
class PartiesController < ApplicationController
before_action :set_party, only: [:show, :edit, :update, :destroy]
# GET /parties
# GET /parties.json
def index
@parties = Party.all
end
# GET /parties/1
# GET /parties/1.json
def show
end
# GET /parties/new
def new
@party = Party.new
end
# GET /parties/1/edit
def edit
end
# POST /parties
# POST /parties.json
def create
@party = Party.new(party_params)
respond_to do |format|
if @party.save
format.html { redirect_to @party, notice: 'Party was successfully created.' }
format.json { render :show, status: :created, location: @party }
else
format.html { render :new }
format.json { render json: @party.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /parties/1
# PATCH/PUT /parties/1.json
def update
respond_to do |format|
if @party.update(party_params)
format.html { redirect_to @party, notice: 'Party was successfully updated.' }
format.json { render :show, status: :ok, location: @party }
else
format.html { render :edit }
format.json { render json: @party.errors, status: :unprocessable_entity }
end
end
end
# DELETE /parties/1
# DELETE /parties/1.json
def destroy
@party.destroy
respond_to do |format|
format.html { redirect_to parties_url, notice: 'Party was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_party
@party = Party.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def party_params
params.require(:party).permit(:latitude, :longitude, :address, :description, :title, :image)
end
end
user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, #:confirmable,
:recoverable, :rememberable, :trackable, :validatable
has_many :parties
validates :name, presence: true
#validates :email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+edu)\z/ }
end