我有一个简单的表单,用户可以在其中编辑内容。如果用户进入编辑操作,则表单会预填充其知道的信息。但是,这仅适用于开发。在暂存和生产服务器上,这不起作用。 如果用户填写编辑操作的空白字段,则会正常更新。
= form_for [@upload, @seller], :url => upload_seller_path(@upload, @seller) do |form|
= render 'error_messages', :subject => form.object
%h2 Edit information
.form-group
= form.label :first_name
= form.text_field :first_name, class: 'form-control'
.form-group
= form.label :last_name
= form.text_field :last_name, class: 'form-control'
.form-group
= form.label :address
= form.text_field :address, class: 'form-control'
.form-group
= form.label :city
= form.text_field :city, class: 'form-control'
= form.submit class: 'btn btn-primary'
= link_to 'Cancel', upload_seller_path(@upload), class:'btn btn-default'
控制器
class IncompleteSellersController < ApplicationController
before_filter :set_upload
before_filter :set_seller, except: [:index]
def update
if @seller.update(sellers_params)
redirect_to upload_incomplete_sellers_path(@upload)
else
render :edit
end
end
private
def set_upload
@upload = Upload.find(params[:upload_id])
end
def set_seller
@seller = @upload.sellers.find(params[:id])
end
def sellers_params
params.require(:seller).permit(:first_name, :last_name, :address, :city)
end
end
我尝试添加value: @seller.address
,但它无效。
知道事情可能出错吗?