Просмотр поста

.
No-Tactic

Koenig, вот на рельсах
оно же на гитхабе, только нужно копаться в файлах https://github.com/n0-tactic/testapp
Контроллер

# coding: utf-8

class PostsController < ApplicationController

  def index
    @posts = Post.all
  end

  def show
    redirect_to :action => "index"
  end

  def new
    @post = Post.new
  end

  def create
    @post = Post.create(params[:post])
    if @post.errors.empty?
      redirect_to post_path(@post)
    else
      render "new"
    end
  end

  def destroy
    @post = Post.where(id: params[:id]).first
    render_404 unless @post

    @post.destroy
    redirect_to action: :index
  end

end


модель
class Post < ActiveRecord::Base
  attr_accessible :name, :email, :text
  validates :name, :email, :text, presence: true
  validates :name, length: { minimum: 3, maximum: 64}
  validates :email, length: { minimum: 5, maximum: 128 }
  validates :email, format: { with: /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i }

end


шаблон главной страницы
<h1>Гостевая книга</h1>

<% if @posts.empty? %>
  <b>Пока нет сообщений. Будешь первым?<b><br/>
<% else %>
  <table>
    <% @posts.each do |i| %>
      <tr>
        <td>
          <%= i.name %><br/>
          <%= i.email %>
        </td>
        <td><%= i.text %></td>
      </tr>
    <% end %>
  </table>
<% end %>
<%= link_to 'Написать', new_post_path %>


и шаблон страницы для добавления поста
<h1>Написать</h1>

<%= form_for @post do |f| %>

  <p>Имя:<br/><%= f.text_field :name %></p>
  <p>Email:<br/><%= f.text_field :email %></p>
  <p>Текст:<br/><%= f.text_area :text %></p>
  <p><%= f.submit "Написать" %></p>

<% end %>