是否可以传递像 ':locals => 这样的局部变量? { :f => f }'使用RJS?
在我的“ROOT_RAILS/views/accounts/new.html.erb”中
<% form_for(@account, :remote => true, :url => accounts_path) do |f| %>
<div class="new_account_form">
...
</div>
<% end %>
,我尝试在“ROOT_RAILS/views/accounts/create.js.rjs”中使用 RJS 来替换这样的 html
page.replace_html :new_account_form, :partial => "/users/accounts/new_account_partial", :locals => { :f => f }
,但出现错误
undefined local variable or method `f' for <<Class:0x00000...>>
: 'ROOT_RAILS/views/accounts/_ew_account_partial.html.erb' 中的课程我有类似这样的内容:
...
<%= f.label :password %>
...
是否可以传递像 ':locals => 这样的局部变量? { :f => f }' 使用 RJS? 如果是,怎么做?
In my 'ROOT_RAILS/views/accounts/new.html.erb' I have
<% form_for(@account, :remote => true, :url => accounts_path) do |f| %>
<div class="new_account_form">
...
</div>
<% end %>
and I am trying to use RJS in 'ROOT_RAILS/views/accounts/create.js.rjs' to replace html like this
page.replace_html :new_account_form, :partial => "/users/accounts/new_account_partial", :locals => { :f => f }
but I get an error:
undefined local variable or method `f' for <<Class:0x00000...>>
Of course in 'ROOT_RAILS/views/accounts/_ew_account_partial.html.erb' I have something like this:
...
<%= f.label :password %>
...
Is it possible to pass local variables like ':locals => { :f => f }' using RJS? If so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
呃...你的 rjs 没有 f 可用,因为它是从控制器调用的。如果你能做到的话,整个表格应该是部分的。
Uh... your rjs doesn't have f available to it because it's called from the controller. The entire form ought to be in the partial, if you can manage it.