我正在研究ROR应用程序,该应用程序在本地主机上工作正常,但在heroku" http://niveshi.herokuapp.com/portfolio/create "引导程序无效,甚至javascript代码无法正常工作.这是我的宝石文件:
source 'https://rubygems.org'
gem 'rails', '3.2.12'
gem "mongoid", "~> 3.1.0"
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.1.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'less-rails'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'delayed_job_mongoid'
gem 'rb-readline', '~> 0.4.2'
gem 'mechanize'
gem 'debugger'
gem 'twitter-bootstrap-rails'
Run Code Online (Sandbox Code Playgroud)
任何我猜对错的猜测.
这是我的代码.
class Product < ActiveRecord::Base
attr_accessible :name, :price, :released_on
begin
validates :name, uniqueness: true
rescue ActiveRecord::RecordInvalid => e
render( inline: "RESCUED ActiveRecord::RecordInvalid" )
return
end
def self.to_csv(options = {})
CSV.generate(options) do |csv|
csv << column_names
all.each do |product|
csv << product.attributes.values_at(*column_names)
end
end
end
def self.import(file)
CSV.foreach(file.path , headers:true) do |row|
Product.create! row.to_hash # If we want to add a new item
end
end
end
Run Code Online (Sandbox Code Playgroud)
当我保存具有相同名称的重复模型时,会引发异常
ProductsController #import中的ActiveRecord :: RecordInvalid
Validation failed: Name has already been taken
Rails.root: /home/deepender/396-importing-csv-and-excel/store-before
Run Code Online (Sandbox Code Playgroud)
我正在使用救援操作仍然没有处理错误?任何我猜对错的猜测.