No tak ale czemu? W bazie dane sa, lądują tam z automatu, bo oba pola zostaly stworzone jak sie mozna domyslic automatycznie i jak zapisuje cos na stronie, dodaje jakis post to dane tam laduja razem z tymi dwoma polami. Tylko czemu nie chce sie to pojawic z powrotem. Co do tego jka to jest zorganizowane itp:
rails -v
Rails 2.2.2
serwer mongrel
postgres --version
postgres (PostgreSQL) 8.2.7
uname -a
Linux gotar 2.6.22-gentoo-r5 #9 SMP Sun Feb 17 00:17:41 CET 2008 i686 AMD Athlon™ XP 2600+ AuthenticAMD GNU/Linux
Gentoo tak w nawiasie
gem list
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (2.2.2, 2.1.2)
actionpack (2.2.2, 2.1.2)
activerecord (2.2.2, 2.1.2)
activeresource (2.2.2, 2.1.2)
activesupport (2.2.2, 2.1.2)
addressable (2.0.1)
cgi_multipart_eof_fix (2.5.0)
daemons (1.0.10)
data_objects (0.9.9)
diff-lcs (1.1.2)
dm-aggregates (0.9.8)
dm-core (0.9.8)
dm-migrations (0.9.8)
dm-sweatshop (0.9.8)
dm-timestamps (0.9.8)
dm-types (0.9.8)
dm-validations (0.9.8)
do_postgres (0.9.9)
do_sqlite3 (0.9.9)
erubis (2.6.2)
extlib (0.9.9)
fastthread (1.0.1)
gem_plugin (0.2.3)
haml (2.0.6)
highline (1.5.0)
hoe (1.8.2)
json_pure (1.1.3)
launchy (0.3.2)
mailfactory (1.4.0)
merb (1.0.6.1)
merb-action-args (1.0.6.1)
merb-assets (1.0.6.1)
merb-auth (1.0.6.1)
merb-auth-core (1.0.6.1)
merb-auth-more (1.0.6.1)
merb-auth-slice-password (1.0.6.1)
merb-cache (1.0.6.1)
merb-core (1.0.6.1)
merb-exceptions (1.0.6.1)
merb-gen (1.0.6.1)
merb-haml (1.0.6.1)
merb-helpers (1.0.6.1)
merb-mailer (1.0.6.1)
merb-more (1.0.6.1)
merb-param-protection (1.0.6.1)
merb-slices (1.0.6.1)
merb_datamapper (1.0.6.1)
merb_helpers (0.9.7)
mime-types (1.15)
mongrel (1.1.5)
ParseTree (3.0.2)
postgres (0.7.9.2008.01.28)
rack (0.4.0)
rails (2.2.2, 2.1.2)
rake (0.8.3)
randexp (0.1.4)
RedCloth (4.1.1)
rspec (1.1.11)
ruby-postgres (0.7.1.2006.04.06)
ruby2ruby (1.2.1)
rubyforge (1.0.1)
RubyInline (3.8.1)
sexp_processor (3.0.0)
templater (0.5.0)
thor (0.9.9)
webrat (0.3.2)
ZenTest (3.11.0)
development: &defaults
adapter: postgresql
database: blog
username: gotar
password:
host: localhost
controller:
class PostsController < ApplicationController
before_filter :authorize, :except => [:index, :show]
GET /posts
GET /posts.xml
def index
@posts = Post.search(params[:search])
if @posts.size.zero?
redirect_to ("/nothing")
else
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts }
format.atom
end
end
end
GET /posts/1
GET /posts/1.xml
def show
@post = Post.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @post }
end
end
model:
class Post < ActiveRecord::Base
validates_presence_of :body, :title
has_many :comments
def self.search(search)
if search
@ile = find(:all, :conditions => [‘title || body ILIKE ?’, “%#{search}%”])
else
find(:all)
end
end
end
widok:
<% div_for post do %>
#<%= @i %>
<% @i = @i+1 %>
<%= link_to_unless_current h(post.title), post %>
<%= textilize(post.body) %>
<p class="right">
<% if post.comments.count.to_i == 1 %>
<%= post.comments.count %> comment</p>
<% else %>
<%= post.comments.count %> comments</p>
<% end %>
<small class="right"><%= (post.created_at) %></small>
<% end %>