Skip to content
Browse files

Add project homepage

  • Loading branch information...
1 parent 6407863 commit 029370c2c65e99dcaf756b3b223e56ef849a3802 tuff_ghost committed
View
5 app/controllers/posts_controller.rb
@@ -1,4 +1,9 @@
class PostsController < ApplicationController
+
+ def home
+ @randomPost = Post.find(:first, :offset => rand(Post.all.size-1))
+ end
+
# GET /posts
# GET /posts.xml
def index
View
2 app/views/layouts/application.html.erb
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
- <title>Otwtraining</title>
+ <%= yield :head %>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag "jquery-1.5.min.js", "jquery.rails.js" %>
<%= csrf_meta_tag %>
View
4 app/views/posts/edit.html.erb
@@ -1,3 +1,7 @@
+<% content_for :head do %>
+ <title>Edit post</title>
+<% end %>
+
<h1>Editing post</h1>
<%= render 'form' %>
View
33 app/views/posts/home.html.erb
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <% content_for :head do %>
+ <title>Posts</title>
+ <% end %>
+
+
+ </head>
+ <body>
+ <div id="page">
+
+ <div id="content">
+ <div id="header">
+ <h1>OTW training</h1>
+ <h2>posts project homepage</h2>
+ </div>
+
+ <p><%= link_to "Posts index", posts_path %></p>
+ <p><%= link_to "New post", new_post_path %></p>
+
+
+ <h3><em>featured post:</em> <%= @randomPost.title %></h3>
+ <%= @randomPost.body %></p>
+
+
+
+ </div>
+
+ <div id="footer">&nbsp;</div>
+ </div>
+ </body>
+</html>
View
6 app/views/posts/index.html.erb
@@ -1,5 +1,11 @@
+<% content_for :head do %>
+ <title>Index</title>
+<% end %>
+
<h1>Listing posts</h1>
+<%= link_to 'homepage', "/posts" %>
+
<table>
<tr>
<th>Title</th>
View
4 app/views/posts/new.html.erb
@@ -1,3 +1,7 @@
+<% content_for :head do %>
+ <title>New post</title>
+<% end %>
+
<h1>New Post</h1>
<%= render 'form' %>
View
4 app/views/posts/show.html.erb
@@ -1,3 +1,7 @@
+<% content_for :head do %>
+ <title><%= @post.title %></title>
+<% end %>
+
<p id="notice"><%= notice %></p>
<p>
View
11 config/routes.rb
@@ -1,6 +1,15 @@
Otwtraining::Application.routes.draw do
- resources :posts
+ get "/posts" => "posts#home"
+
+ get "/posts/index" => "posts#index", :as => :posts
+ post "/posts/index" => "posts#create", :as => :posts
+
+ # get "/admin/posts/new" => "posts#new"
+ # match "/posts/new" => redirect("/admin/posts/new")
+
+ resources :posts, :path_names => { :new => "admin/posts/new" }
+
# The priority is based upon order of creation:
# first created -> highest priority.

0 comments on commit 029370c

Please sign in to comment.
Something went wrong with that request. Please try again.