我有这些模型(为便于阅读而简化):
class Place < ActiveRecord::Base
has_many :business_hours, dependent: :destroy
accepts_nested_attributes_for :business_hours
end
class BusinessHour < ActiveRecord::Base
belongs_to :place
end
Run Code Online (Sandbox Code Playgroud)
而这个控制器:
class Admin::PlacesController < Admin::BaseController
def update
@place = Place.find(params[:id])
if @place.update_attributes(place_params)
# Redirect to OK page
else
# Show errors
end
end
private
def place_params
params.require(:place)
.permit(
business_hours_attributes: [:day_of_week, :opening_time, :closing_time]
)
end
end
Run Code Online (Sandbox Code Playgroud)
我有一个动态的表单,通过javascript呈现,用户可以添加新的开放时间.提交这些开放时间时,我想总是替换旧的(如果存在的话).目前,如果我通过params发送值(例如):
place[business_hours][0][day_of_week]: 1
place[business_hours][0][opening_time]: 10:00 am
place[business_hours][0][closing_time]: 5:00 pm
place[business_hours][1][day_of_week]: 2
place[business_hours][1][opening_time]: 10:00 am
place[business_hours][1][closing_time]: 5:00 pm
Run Code Online (Sandbox Code Playgroud)
......等等
这些新的营业时间会添加到现有营业时间.有没有办法告诉rails总是替换营业时间,还是我每次都要手动清空控制器中的集合?
我想知道是否有办法在Rails 3.1中更改新资产管道位置的默认URL. - 默认URL是/ assets - 我想将其更改为/ static
我的问题是我已经有了一个Asset模型,它可能会干扰URL.
我知道有一种方法可以为资产指定不同的主机(config.asset_host),但我宁愿不去求助.
谢谢!