我有一个表单partial,它需要根据从调用方视图传递给它的局部变量的值来呈现remote_form_for或form_for。看起来像是..。
<% if ajax %>
<% remote_form_for @search, :url => {:action => :search_set, :controller => :searches, :stype => stype} do |f| %>
<% else %>
<% form_for @search, :url => {:action => :search_set, :controller => :searches, :stype => stype} do |f| %>
<% end %>显然,我在<%else %>附近得到了一个语法错误,因为它需要一个"end“。
这样做的正确方法是什么?
发布于 2010-06-05 03:52:27
您可以创建一个helper方法
def form_or_remote_form_for object, *opts, &proc
if ajax
remote_form_for object, *opts, &proc
else
form_for object, *opts, &proc
end
end在你看来,它就是
<% form_or_remote_form_for @search, :url => {:action => :search_set, :controller => :searches, :stype => stype} do |f| %>https://stackoverflow.com/questions/2976297
复制相似问题