Ruby on rails 为什么赢了';我的简单Rails表单\标记搜索表单是否使用正确的方法提供结果?
我从一个小的搜索表单开始,并试图让基本的工作。提前感谢您提供的任何帮助 我正在编辑一个Rails2.3遗留应用程序并修改它的旧搜索表单。现在,它只有一个字段,用于文本搜索我数据库中的位置(通过匹配城市)。当我提交表单时,它从“URL/搜索位置”变为“URL/搜索位置?城市=洛杉矶”,但不显示结果。根据我的日志,我认为问题在于它没有呈现正确的视图 表单页面(index.html.erbRuby on rails 为什么赢了';我的简单Rails表单\标记搜索表单是否使用正确的方法提供结果?,ruby-on-rails,forms,ruby-on-rails-2,Ruby On Rails,Forms,Ruby On Rails 2,我从一个小的搜索表单开始,并试图让基本的工作。提前感谢您提供的任何帮助 我正在编辑一个Rails2.3遗留应用程序并修改它的旧搜索表单。现在,它只有一个字段,用于文本搜索我数据库中的位置(通过匹配城市)。当我提交表单时,它从“URL/搜索位置”变为“URL/搜索位置?城市=洛杉矶”,但不显示结果。根据我的日志,我认为问题在于它没有呈现正确的视图 表单页面(index.html.erb <% form_tag search_path, :method => 'get' do %
<% form_tag search_path, :method => 'get' do %>
<%= text_field_tag :city, params[:city] %>
<%= submit_tag "Search", :name => nil %>
<% end %>
<% for location in @site_matches %>
<h3><%= location.name %></h3>
<% end %>
class SearchController < ApplicationController
def index
render :layout => 'mylayout'
end
def results
@site_matches = Location.find(:all, :conditions => ["city = ?", params[:city]])
render :layout => 'mylayout'
end
end
路线
map.resources :search
map.search '/search-for-locations', :controller => 'search', :action => 'index'
再次感谢您的帮助!经过多次尝试和错误,我发现问题在于我的“结果”操作没有呈现“获取”视图。我将以下内容添加到我的路线中:
map.resources :search, :collection => { :index => :get, :results => :get }
我还将我的表单标签改为
<% form_tag url_for(:controller => 'search', :action => 'results'), :method => 'get' do %>
'search',:action=>'results'),:method=>'get'do%>
现在一切都好了
<% form_tag url_for(:controller => 'search', :action => 'results'), :method => 'get' do %>