我有一个带有一些嵌套属性模型的事件表单。在从选择框中选择客户端后,将呈现附加模型。观察者监视并调用控制器动作,该动作呈现包含 fields_for 嵌套模型的部分。我遇到的问题是我无法将事件“表单”块传递给新渲染的部分 - 至少我不知道如何......
下面的代码引发了错误:“参数数量错误(0 代表 1)”。任何帮助或建议表示赞赏。如下所述,如果您可以为此场景提供示例,我也愿意使用不显眼的 JavaScript 重新实现它。
活动形式:
<%- form_for @event do |form| %>
<%= select_tag :id=>event_client_id %>
<%= observe_field :event_client_id, url => {:action => 'client_questions'}, :with => "'client_id=' + encodeURIComponent(value)+'&event_id='+#{@event.id} %>
事件控制器
def client_questions
@event = Event.find(params[:event_id])
@client = Client.find(params[:client_id])
@client_questions = @client.questions.active
respond_to do |format|
format.js {
render :update do |page|
page[:client_questions].replace_html :partial => 'client_questions', :layout => false
end
}
end
end
_client_questions.html.erb 部分
<%- form.fields_for :client, @client do |client| %>
<%= client_text_field :name %>
<%- client.fields_for :questions do |question| %>
<%=question.text_field :content %>