如何將rails2.0 的程式碼改成 1.2 ?

0 views
Skip to first unread message

Ruby on Rails

unread,
Aug 19, 2008, 7:05:25 AM8/19/08
to Ruby on Rails Taiwan
(views\timeformats\index.html.erb)

<h1>Listing timeformats</h1>
<% form_tag timeformats_path , :method => 'get' do %>
<p>
<%= text_field_tag :search , params[:serach] %>
<%= submit_tag "??" , :title => nil %>
</p>
<% end %>

<table>
<tr>
<th>Title</th>
<th>Datetime</th>
</tr>

<% for timeformat in @timeformats %>
<tr>
<td><%=h timeformat.title %></td>
<td><%=h timeformat.datetime.strftime('%m/%d/%Y %I:%M %p') %></td>
<td><%= link_to 'Show', timeformat %></td>
<td><%= link_to 'Edit', edit_timeformat_path(timeformat) %></td>
<td><%= link_to 'Destroy', timeformat, :confirm => 'Are you
sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= 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
Reply all
Reply to author
Forward
0 new messages