Neue Fehlermeldung: NoMethodError in OffersController#create

Fragen zur Controllerprogrammierung, Actions & Vermittlung zwischen Model und View

Neue Fehlermeldung: NoMethodError in OffersController#create

Beitragvon Lee01 am 12.12.2011, 21:25

undefined method `original_filename' for "auspuff-bmw.jpg":String


was ich nicht verstehe: Die Methode original_filename ist doch in ActionController definiert, wo ist da das Problem?

Kann mir da jemand helfen?

Hier ist der Controller:
Code: Alles auswählen
class OffersController < ApplicationController
      layout("standard")
  def new
     @offer = Offer.new
  end

  def create
  @offer = Offer.new(params[:offer])
    if @offer.valid? == false
        flash.now[:notice] = "Bitte machen Sie Angaben zu Artikelbezeichnung und Zustand"
        render(:action => :new)
             elsif !@offer.save_files
                  flash.now[:notice] = "Es trat ein Fehler beim Hochladen der Dateien auf."
                  render(:action => :new)
             else
                @offer.save
                flash[:notice] = "Die Angebotsdaten wurden erfolgreich gespeichert."
                redirect_to(:action => :list)
       end
  end

  def list
       @offers = Offer.find(:all, :order => 'created_at DESC')
  end

  def edit
      @offer = Offer.find(params[:id])
  end

def update
     @offer = Offer.find(params[:id])
  if @offer.update_attributes(params[:offer]) and @offer.save_files
      flash[:notice] = "Ihre Änderungen wurden gespeichert."
      redirect_to(:action => :list)
  else
      flash.now[:notice] = "Es trat ein Fehler auf. Bitte füllen Sie alle Felder aus und überprüfen Sie Ihre Angaben."
      render(:action => :edit)
  end

end

  def delete
    @offer = Offer.destroy(params[:id])
    flash[:notice] = "Das Angebot '#{@offer.artikelbezeichnung}' wurde gelöscht."
    redirect_to(:action => :list)
end

  def show
  @offer = Offer.find(params[:id])
  end

  def index
  @latest_offers = Offer.find(:all, :limit => 3, :order => 'created_at DESC')
  end

end


Und hier das Model:

Code: Alles auswählen
class Offer < ActiveRecord::Base
  validates_presence_of(:artikelbezeichnung, :zustand)
def image_file= (fileobj)
  if fileobj.size > 0
  @image_file = fileobj
  self.image_file = fileobj.original_filename
  end
end

  def thumbnail_file= (fileobj)
    if fileobj.size > 0
    @thumbnail_file = fileobj
    self.thumbnail = fileobj.original_filename
    end
  end

  def save_uploaded_file(fileobj, filepath, filename)
  complete_path = RAILS_ROOT + '/public/' + filepath
  FileUtils.mkdir_p(complete_path) unless File.exists?(complete_path)
    begin
     f = File.open(complete_path + '/' + filename, 'wb')
     f.write(fileobj.read)
    rescue
    return false
    ensure
    f.close unless f.nil?
    end
  end

def save_files
if !save_uploaded_file(@image_file, IMAGE_DIR, self.image)
  return false
end
  if !save_uploaded_file(@thumbnail,THUMBNAIL_DIR,self.thumbnail)
    return false
  end
  return true
end
  def before_destroy
imagefile = RAILS_ROOT + '/public/' + IMAGE_DIR + '/' + self.image
thumbnailfile = RAILS_ROOT + '/public/' + THUMBNAIL_DIR + '/' + self.thumbnail
File.delete(imagefile) if File.exists?(imagefile)
File.delete(thumbnailfile) if File.exists?(thumbnailfile)
  end
end



Danke schonmal für Eure Antworten! :)
Lee01
 
Beiträge: 2
Registriert: 04.12.2011, 19:01

Zurück zu C - Controller

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast

cron