Created
August 29, 2009 10:37
-
-
Save anonymous/177457 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% @listakategori.each do |listakategori| %> | |
<#%= link_to listakategori.name, listakategori %> | |
<%= link_to listakategori.name, { :action => "wgkategori" } %> | |
<% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="secondaryContent"> | |
<h3>Lista wpisów</h3> | |
<%= render :partial => "listapostow" %> | |
<!-- alternatywa <#%= render :partial => "listapostow", :collection => @posts %> --> | |
<h3>Lista kategorii</h3> | |
<%= render :partial => "listakategori" %> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<!-- | |
Design by Free CSS Templates | |
http://www.freecsstemplates.org | |
Released for free under a Creative Commons Attribution 2.5 License | |
--> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | |
<title>Emerald by Free CSS Templates</title> | |
<meta name="keywords" content="" /> | |
<meta name="description" content="" /> | |
<%= stylesheet_link_tag 'scaffold', 'home' %> | |
</head> | |
<body> | |
<div id="outer"> | |
<div id="header"> | |
<h1><a href="#">Emerald</a></h1> | |
<h2>by Free CSS Templates</h2> | |
</div> | |
<div id="menu"> | |
<ul> | |
<li class="first"><a href="#" accesskey="1" title="">Home</a></li> | |
<li><a href="#" accesskey="2" title="">About Us</a></li> | |
<li><a href="#" accesskey="3" title="">Products</a></li> | |
<li><a href="#" accesskey="4" title="">Services</a></li> | |
<li><a href="#" accesskey="5" title="">Contact Us</a></li> | |
</ul> | |
</div> | |
<div id="content"> | |
<div id="primaryContentContainer"> | |
<div id="primaryContent"> | |
<%= yield %> | |
</div> | |
<div class="clear"></div> | |
<div id="footer"> | |
<p>Copyright © 2007 Sitename.com. Designed by <a href="http://www.freecsstemplates.org">Free CSS Templates</a></p> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cat < ActiveRecord::Base | |
has_many :posts | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CatsController < ApplicationController | |
# GET /cats | |
# GET /cats.xml | |
def index | |
@cats = Cat.all | |
respond_to do |format| | |
format.html # index.html.erb | |
format.xml { render :xml => @cats } | |
end | |
end | |
# GET /cats/1 | |
# GET /cats/1.xml | |
def show | |
@cat = Cat.find(params[:id]) | |
respond_to do |format| | |
format.html # show.html.erb | |
format.xml { render :xml => @cat } | |
end | |
end | |
# GET /cats/new | |
# GET /cats/new.xml | |
def new | |
@cat = Cat.new | |
respond_to do |format| | |
format.html # new.html.erb | |
format.xml { render :xml => @cat } | |
end | |
end | |
# GET /cats/1/edit | |
def edit | |
@cat = Cat.find(params[:id]) | |
end | |
# POST /cats | |
# POST /cats.xml | |
def create | |
@cat = Cat.new(params[:cat]) | |
respond_to do |format| | |
if @cat.save | |
flash[:notice] = 'Cat was successfully created.' | |
format.html { redirect_to(@cat) } | |
format.xml { render :xml => @cat, :status => :created, :location => @cat } | |
else | |
format.html { render :action => "new" } | |
format.xml { render :xml => @cat.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
# PUT /cats/1 | |
# PUT /cats/1.xml | |
def update | |
@cat = Cat.find(params[:id]) | |
respond_to do |format| | |
if @cat.update_attributes(params[:cat]) | |
flash[:notice] = 'Cat was successfully updated.' | |
format.html { redirect_to(@cat) } | |
format.xml { head :ok } | |
else | |
format.html { render :action => "edit" } | |
format.xml { render :xml => @cat.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /cats/1 | |
# DELETE /cats/1.xml | |
def destroy | |
@cat = Cat.find(params[:id]) | |
@cat.destroy | |
respond_to do |format| | |
format.html { redirect_to(cats_url) } | |
format.xml { head :ok } | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% @posts.each do |post| %> | |
<h2><%=h post.name %></h2> | |
<p class="small">Kategoria: <%=h post.cat.name %></p> | |
<p><%=h post.title %></p> | |
<p><%=h post.content %></p> | |
<p>Komentarzy: <%=h post.comments.count %></p> | |
<%= link_to 'Show', post %></td> | |
<%= link_to 'Edit', edit_post_path(post) %></td> | |
<%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %></td> | |
<hr/> | |
<% end %> | |
<%= link_to 'New post', new_post_path %> | |
</div> | |
</div> | |
<%= render :partial => "secondaryContent" %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ActiveRecord::Base | |
validates_presence_of :name, :title | |
validates_length_of :title, :minimum => 5 | |
has_many :comments | |
belongs_to :post | |
belongs_to :cat | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostsController < ApplicationController | |
# GET /posts | |
# GET /posts.xml | |
def index | |
@posts = Post.find(:all) | |
@listakategori = Cat.find(:all) | |
respond_to do |format| | |
format.html # index.html.erb | |
format.xml { render :xml => @posts } | |
end | |
end | |
# GET /posts/1 | |
# GET /posts/1.xml | |
def show | |
@post = Post.find(params[:id]) | |
@listakategori = Cat.find(:all) | |
@posts = Post.find(:all) | |
respond_to do |format| | |
format.html # show.html.erb | |
format.xml { render :xml => @post } | |
end | |
end | |
# GET /posts/new | |
# GET /posts/new.xml | |
def new | |
@post = Post.new | |
@kategoria = Cat.find(:all) | |
respond_to do |format| | |
format.html # new.html.erb | |
format.xml { render :xml => @post } | |
end | |
end | |
# GET /posts/1/edit | |
def edit | |
@post = Post.find(params[:id]) | |
@kategoria = Cat.find(:all) | |
end | |
# POST /posts | |
# POST /posts.xml | |
def create | |
@post = Post.new(params[:post]) | |
respond_to do |format| | |
if @post.save | |
flash[:notice] = 'Post was successfully created.' | |
format.html { redirect_to(@post) } | |
format.xml { render :xml => @post, :status => :created, :location => @post } | |
else | |
format.html { render :action => "new" } | |
format.xml { render :xml => @post.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
# PUT /posts/1 | |
# PUT /posts/1.xml | |
def update | |
@post = Post.find(params[:id]) | |
@post.cat_id = (params[:cat]) | |
respond_to do |format| | |
if @post.update_attributes(params[:post]) | |
flash[:notice] = 'Post was successfully updated.' | |
format.html { redirect_to(@post) } | |
format.xml { head :ok } | |
else | |
format.html { render :action => "edit" } | |
format.xml { render :xml => @post.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /posts/1 | |
# DELETE /posts/1.xml | |
def destroy | |
@post = Post.find(params[:id]) | |
@post.destroy | |
respond_to do |format| | |
format.html { redirect_to(posts_url) } | |
format.xml { head :ok } | |
end | |
end | |
def wgkategori | |
@post = Post.find(:all) | |
@kategoria = Cat.find(:all) | |
@posts = Post.find(:all) | |
@listakategori = Cat.find(:all) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2><%=h @post.name %></h2> | |
<p class="small">Kategoria: <%=h @post.cat.name %></p> | |
<p><%=h @post.title %></p> | |
<p><%=h @post.content %></p> | |
</div> | |
<h2>Komentarze</h2> | |
<% @post.comments.each do |c| %> | |
<p><b>Komentarz dodał:</b> <%=h c.commenter %></p> | |
<p><%=h c.body %></p> | |
<hr/> | |
<%= link_to 'Edit Post', edit_post_path(@post) %> | | |
<%= link_to 'Back to Posts', posts_path %> | |
<%= link_to 'Manage Comments', post_comments_path(@post) %> | |
<% end %> | |
</div> | |
</div> | |
<%= render :partial => "secondaryContent" %> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment