0
我正在使用link_to渲染局部(如圖所示,在單擊link_to時渲染局部),如圖所示。我想通過參數u.id到部分,但我沒有成功:(我做錯了什麼?我絕望。在link_to和渲染局部之間傳遞參數
編輯:終於得到它的工作。這是我的代碼:
在我看來,用戶/ show.html.erb - 「U」 是一個集合
<% @utilities.each do |u| %>
<%= link_to u.name, { :controller => :users, :action => :show, :util_id => u.id }, :remote => true %>
<% end %>
在每個工具在我的用戶#結束顯示控制器方法
respond_to do |format|
format.html {
redirect_to @current_user and return
}
format.json {
redirect_to @current_user.json and return
}
format.js {
@util_id = params[:util_id]
redirect_to @current_user and return
}
end
Show.js.erb:
$("#editUtil").prepend('<%= escape_javascript(raw render :partial => "utilEdit", :locals => {:util => params[:util_id]}).html_safe%>');
我的部分:_utilEdit.html.erb
TEST: <%= Utility.find(util).name %>
謝謝大家誰幫助!
謝謝!但我得到錯誤「未定義的方法'show_users_path'爲#<#:0x007fb79b36aa88>」:(: –
user1436111
修復它,它現在可以工作! – user1436111