我有一个带有内部投诉表单的Rails应用程序。当我处于编辑模式时,我希望能够显示,删除和添加用户投诉。
使用partial来显示分配给投诉的用户。
每个用户旁边的删除链接有效。当我单击链接时,将从document_histories表中删除该用户,并刷新具有已分配用户部分的div。
如果我点击链接添加用户,我会弹出一个窗口。将一个或多个用户添加到分配的用户(Document_histories)表中。但是,我无法像删除用户时那样部分刷新。
我有一个可以刷新的按钮,但从可用性的角度来看并不好。我需要在添加用户时自动刷新div / partial。
我无法工作的事情是在将用户添加到投诉的表单关闭后进行div / partial刷新。
我的投诉/ edit.html.erb有
ADate=`date -d"10 days ago"`
BDate=`date -d"$ADate - 30 days" +%s`
echo $BDate
我的document_histories / new controller是
<%= link_to( '<button>Refresh the assigned users list</button>'.html_safe,
#,
remote: true,
controller: 'document_histories',
action: 'new',
) %> <br> # This will manually refresh the partial showing users assigned to the complaint - I want this to happen when the assign users form closes.
<%= link_to( '<button>assign a user</button>'.html_safe,
"/document_histories/new",
'data-popup' => true,
remote: true,
:class => "button_class",
:onclick=>"window.open(this.href,'assign complaint to users', 'height=800, width=500');
script.src= 'create.js.erb';
return false;"
) %> #pops up a new window to add user to complaint(document_histories table)
<div id="refresh_assigned">
<% if @document_histories.count > 0 then %>
<%= render :partial => '/document_histories/history_for_complaint_form', controller: 'document_histories', action: 'new' %>
<% else %>
<h4> There is no document history at this time.. </h4>
<% end %>
</div>
</td>
<%= render 'form' %> # renders the complaint(edit) form
new.js.erb是
def new
@document_history = DocumentHistory.new
@document_histories = DocumentHistory.all
@users = User.uniq.pluck(:name)
@existing_sent_to = DocumentHistory.where(:complaint_id => $document_assign)
@existing_sent_to.each do |remove_existing| #removes users already assigned from the dropdown
@users.delete(remove_existing.sent_to)
end
respond_to do |format|
format.html { render :new }
format.js {}
#format.json { render json: @document_history.errors, status: :unprocessable_entity }
end
end
我将警报框放入,以查看代码执行的时间。当我单击“分配用户”链接时,我会看到警报,并刷新分配的用户列表。提交分配用户表单时,我看不到警报。已分配的用户按预期添加到document_histories表中。但是,在我使用刷新按钮手动更新之前,部分不会更新。
我的document_histories / create是
$('#refresh_assigned').html("<%= escape_javascript(render(:partial => 'document_histories/history_for_complaint_form')).html_safe %>");
alert("new 123");
我有一个带有警告的create.js.erb,让我知道它是否已执行。这似乎没有执行。
我的目标是在将用户添加到投诉后刷新refresh_assigned部分。