如何将以下程式码转换成Rails1.2格式,因为在Rails1.2无法辨识“timeformats_path”
(views\timeformats\index.html.erb)
<% form_tag timeformats_path , :method => 'get' do %>
<%= text_field_tag :search , params[:serach] %>
<%= submit_tag "Search" , :title => nil %>
Title | Datetime | |||
---|---|---|---|---|
'Are you sure?', :method => :delete %> |
<%= link_to 'New timeformat', new_timeformat_path %>
(app\controllers\timeformats_controller.rb)
class TimeformatsController < ApplicationController
# GET /timeformats
# GET /timeformats.xml
def index
@timeformats = Timeformat.search(params[:search])
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @timeformats }
end
end
(app\models\timeformat.rb)
class Timeformat < ActiveRecord::Base
validates_presence_of :title
def self.search(search)
if search
find(:all , :conditions => ['title LIKE ?' , "%#{search}%"])
else
find(:all)
end
end
rails 1.2已经支持REST了,也就是说只要你的路由中定义了以下资源
[code="ruby"]
map.resources :categories :timeformats
[/code]
timeformats_path 是完全合法的。
这个是2.0引入的restful resources的写法,你需要手工修改成用1.2的普通route方式。
不好意思 不小心多加了个 :categories
不需要加那个 呵呵~