我希望更新记录,但不能在同一控制器上的表单中以标准Rails方式更新。我的表格在那里运作良好。我在一个名为Shoes
的不同控制器/视图中有一个表单。
我遇到的问题是用户正在更新的记录不是可以从网址中提取的静态记录(我认为Rails一般是如何提取的 - 我' m学习所以如果我不完全正确的话,请不要因此而毁灭我。当用户点击要添加/更新到client_sub_folder
的项目时,表单中的两个collection_select
选项允许用户选择他们添加的client_folder
和client_sub_folder
然后,这将确定他们添加的项目client_folder
和client_sub_folder
将进入/更新。
我在Designer
模型上使用Devise进行身份验证。
我该怎么做?
我的错误讯息:
No route matches {:action=>"show", :client_folder_id=>nil, :controller=>"client_sub_folders", :name_prefix=>"client_folder_"} missing required keys: [:client_folder_id, :id]
我认为这里需要一些JQuery魔法。
模特:
class Designer < ApplicationRecord
has_many :client_folders, dependent: :destroy
has_many :client_sub_folders, through: :client_folders
accepts_nested_attributes_for :client_folders
accepts_nested_attributes_for :client_sub_folders
end
class ClientFolder < ApplicationRecord
belongs_to :designer
has_many :client_sub_folders, dependent: :destroy
accepts_nested_attributes_for :client_sub_folders
end
class ClientSubFolder < ApplicationRecord
belongs_to :client_folder
end
鞋/ index.html.erb
<%= form_for([Designer.current_designer.client_folders,@sub_client_folder], url: client_folder_client_sub_folder_path(@client_sub_folder), method: :patch) do |f| %>
<%= f.collection_select :client_folders, :client_folder_ids, Designer.current_designer.client_folders, :id, :client_name, {include_blank: true}, {id: "get-folder"} %>
<%= f.grouped_collection_select :client_sub_folders, :client_sub_folder_ids, Designer.current_designer.client_folders.order(:client_name), :client_sub_folders, :client_name, :id, :room_name, {include_blank: true}, {id: "get-sub"} %>
<%= f.submit %>
<% end %>