在我的控制器中我有这个:
def hours_create
@hour = params[:hour].map { |hour_attrs| Hour.create(hour_attrs) }
if @hour.save
redirect_to :back, notice: "hour created."
else
render :new
end
end
Run Code Online (Sandbox Code Playgroud)
错误来自@hour.save但不确定要替换它的原因,因为当项目保存到我的数据库中时,我需要以某种方式重定向页面?
为什么会出现这个错误?
谢谢
当jQuery生成新字段时,新字段不能与'enter'一起使用.
这是我的脚本:
咖啡
$('.teaser-form').keyup (e) ->
if e.keyCode == 13
$('.add-new-list').click()
Run Code Online (Sandbox Code Playgroud)
form.haml
= f.simple_fields_for :products do |p|
= render 'product_fields', :f => p
.gear-item-add
= link_to_add_association 'add item', f, :gears, class: "btn btn-default add-new-list"
Run Code Online (Sandbox Code Playgroud)
所以jQuery调用link_to_add_association按钮创建下面显示的字段.(第一个字段是初始字段,所以如果按下回车键,则会产生第二个字段和第三个字段...但如果我尝试继续第三个字段并按Enter键,则不会发生任何事情)
_product_field.haml
.nested-fields.gear-patrol
.col-md-12
= f.text_field :list, class: 'teaser-form form-control', placeholder: 'testing'
Run Code Online (Sandbox Code Playgroud)
在我的表单中,它显示了我的策略和x-amz凭证,x-amz-算法,x-amz签名,我的存储桶等...
data-form-data = "{"key":"/uploads/temporary/<some random numbers/letters>/${filename}",
"success_action_status":"201",
"acl":"public-read",
"Content-Type":"image/jpeg",
"policy":"<bunch of random numbers/letters",
"x-amz-credential":"<your-access-key-id>/<date>/<aws-region>/<aws-service>/aws4_request",
"x-amz-algorithm":"<some random numbers/lettering>",
"x-amz-date":"<some random numbers/letters>",
"x-amz-signature":"<some random numbers/letters>"}"
data-url="https://<bucket-name>.s3.amazonaws.com"
data-hose="<bucket-name>.s3.amazonaws.com
Run Code Online (Sandbox Code Playgroud) 我正在使用Rails 5,并且已经安装了gem并尝试运行迁移,但是却出现此错误:
Index name 'index_rates_on_rater_id' on table 'rates' already exists
有人知道为什么会这样吗?这是一个新站点,并且刚刚开始添加devise gem。
这是在执行时无法完成的迁移文件 rails db:migrate
class CreateRates < ActiveRecord::Migration[5.1]
def self.up
create_table :rates do |t|
t.belongs_to :rater
t.belongs_to :rateable, :polymorphic => true
t.float :stars, :null => false
t.string :dimension
t.timestamps
end
add_index :rates, :rater_id
add_index :rates, [:rateable_id, :rateable_type]
end
def self.down
drop_table :rates
end
end
Run Code Online (Sandbox Code Playgroud)