Ruby on Rails
unread,Aug 19, 2008, 7:05:25 AM8/19/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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