HY 簡單的搜索我試圖在我的應用程序創建一個簡單的搜索與軌道
calendar.rb
def self.search(search_condition)
search_condition = "%" + search + "%"
find(:all, :conditions => ['city like ?', search_condition])
end
calendar_controller.rb
def index
@search = @user.calendar.search(params[:search_condition])
@content_calendars = @user.calendar.all
@content_calendars_by_dates = @content_calendars.group_by(&:published_on)
@date = params[:date] ? Date.parse(params[:date]) : Date.today
end
部分_search.html.erb
<%= form_tag root_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search_condition], :id => 'search_field' %>
<%= submit_tag "Search", :name => nil %>
<% end %
當我嘗試我得到這個錯誤:
The request method POST is inappropriate for the URL /.
我不明白爲什麼?
耙路線
user_calendars GET /users/:user_id/calendars(.:format) calendars#index
POST /users/:user_id/calendars(.:format) calendars#create
new_user_calendar GET /users/:user_id/calendars/new(.:format) calendars#new
edit_user_calendar GET /users/:user_id/calendars/:id/edit(.:format) calendars#edit
user_calendar GET /users/:user_id/calendars/:id(.:format) calendars#show
你的根路徑設置爲什麼? – CoolTapes
我嘗試在我的索引中獲得所有搜索結果。 root to =>「home#index」rake routes root/home#index – zyriuse