所以我有一个颜色调色板的表格,我想现场更新,我已经坚持这个问题好几天了。
这是我的更新控制器
def update
@project = Project.find_by(id: params[:id])
binding.pry
@palette = @project.palette
unless @project
render json: {error: "project not found"},
status: 404
return
end
@project.update(project_params)
@project.update_palette(palette_params)
render json: project
end
一个项目有一个调色板
private
def project_params
params.require(:project).permit(:name, :option, :id, :background_dark_color, :background_light_color, :dark_color1, :dark_color2, :light_color1, :light_color2)
end
def palette_params
params.require(:palette).permit(:background_dark_color, :background_light_color, :dark_color1, :dark_color2, :light_color1, :light_color2) #=> [ :id, :name, :_destroy ])
end
错误是向我投掷http://codepen.io/huggaf/pen/XKYoKW/
添加表单
<%= palette.label 'background_dark_color' %>:
<%= palette.text_field :background_dark_color, maxlength: 6, placeholder: "#{@project.palette}" %><br/>
<%= palette.label 'background_light_color' %>:
<%= palette.text_field :background_light_color, maxlength: 6, placeholder: "#{@project.palette}" %><br/>
<%= palette.label 'dark_color1' %>:
<%= palette.text_field :dark_color1, maxlength: 6, placeholder: "#{}" %><br/>
<%= palette.label 'dark_color2' %>:
<%= palette.text_field :dark_color2, maxlength: 6, placeholder: "#{@project.palette}" %><br/>
<%= palette.label 'light_color1' %>:
<%= palette.text_field :light_color1, maxlength: 6, placeholder: "#{@project.palette}" %><br/>
<%= palette.label 'light_color2' %>:
<%= palette.text_field :light_color2, maxlength: 6, placeholder: "#{@project.palette}" %><br/>
<%= palette.submit %>
<%= link_to 'Destroy', project, method: :delete %>
<!-- , data: { confirm: 'Are you sure?' } this is the confirm message and sucks, better use "undo" -->
<% end %>