我有service
按预期工作。我遇到了js回归的麻烦。
:remote => true
然后在def myfunc
...
respond_to do |format|
if !response.nil?
r = response.to_hash
format.js { render :json => {:IsLoggedIn => true, :response => r }}
format.html
else
@error = "Try again"
format.js { render :json => {:IsLoggedIn => false, :response => @error }}
format.html
end
end
end
我如何获得myfunc.js.erb
& IsLoggedIn
值?
答案 0 :(得分:0)
根据您的情况,您仅对js使用此功能。所以写下面就好了:
def myfunc
...
@r = response
end
在myfunc.js.erb
中,请写下以下内容:
<% if @r.present? %>
{:IsLoggedIn => true, :response => @r }
<% else %>
{:IsLoggedIn => true, :response => "Try Again" }
<% end %>
@r is available in js.erb , so you set it your html div like $("#yourdivid").val("<%= @r.id" %>")