Good Day , I have an error while uploading csv file and also as image uploading into my webpage Error NoMethodError in ImagesController#import undefined method `import' for Image:Class Iam fresher into the ruby on rails plz help me out
Model/image.rb
class Image < ApplicationRecord
has_one_attached :avatar
end
def self.import
CSV.foreach(file.path, headers: true) do |row|
Image.create! row.to_hash
end
end
controller/images_controller.rb
def import
Image.import(params[:file])
redirect_to images_path, notice: "excel import successfully"
end
Aucun commentaire:
Enregistrer un commentaire