稍微看了一下,好像挺简单,只是处理了一下参数。
# Automatically makes the form method :get if a Searchlogic::Search and sets
# the params scope to :search
def form_for(*args, &block)
if search_obj = args.find { |arg| arg.is_a?(Searchlogic::Search) }
options = args.extract_options!
options[:html] ||= {}
options[:html][:method] ||= :get
options[:url] ||= url_for
args.unshift(:search) if args.first == search_obj
args << options
end
super
end
#照抄着上面写了个remote_form_for
def remote_form_for(*args, &block)
if search_obj = args.find { |arg| arg.is_a?(Searchlogic::Search) }
options = args.extract_options!
options[:html] ||= {}
options[:method] ||= :get #改了一下这里就可以正常使用了。
options[:url] ||= url_for
args.unshift(:search) if args.first == search_obj
args << options
end
super
end
本文介绍了一种简化Rails应用中搜索表单的方法。通过修改form_for和remote_form_for方法,可以自动将搜索请求设置为GET方法,并调整参数作用域。这种方法提高了表单处理效率。
6282

被折叠的 条评论
为什么被折叠?



