Created
June 15, 2013 17:06
-
-
Save Apane/5788776 to your computer and use it in GitHub Desktop.
This file contains 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
<%= form_for(@status) do |f| %> | |
<% if @status.errors.any? %> | |
<div id="error_explanation"> | |
<h2><%= pluralize(@status.errors.count, "error") %> prohibited this status from being saved:</h2> | |
<ul> | |
<% @status.errors.full_messages.each do |msg| %> | |
<li><%= msg %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<div class="field"> | |
<%= f.label :content %><br> | |
<%= f.text_area :content %> | |
</div> | |
<div class="actions"> | |
<%= f.submit %> | |
</div> | |
<% end %> |
This file contains 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 class="page-header"> | |
<h1>All of the Statuses</h1> | |
</div> | |
<%= link_to "Post a new status", new_status_path, class: "btn btn-primary" %> | |
<% @statuses.each do |status| %> | |
<div class="status"> | |
<strong><%#= status.name %></strong> | |
<p><%= status.content %></p> | |
<div class="meta"> | |
<%= link_to time_ago_in_words(status.created_at) + " ago", status %> | |
<span class="admin">| <%= link_to "Edit", edit_status_path(status) %> | | |
<%= link_to "Delete", status, method: :delete, data: { confirm: "Are you sure you want to delete this status?" } %></span> | |
</div> | |
</div> | |
<% end %> |
This file contains 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
<p id="notice"><%= notice %></p> | |
<p> | |
<strong>Name:</strong> | |
<%#= @status.name %> | |
</p> | |
<p> | |
<strong>Content:</strong> | |
<%= @status.content %> | |
</p> | |
<%= link_to 'Edit', edit_status_path(@status) %> | | |
<%= link_to 'Back', statuses_path %> |
This file contains 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 StatusesController < ApplicationController | |
before_action :set_status, only: [:show, :edit, :update, :destroy] | |
# GET /statuses | |
# GET /statuses.json | |
def index | |
@statuses = Status.all | |
end | |
# GET /statuses/1 | |
# GET /statuses/1.json | |
def show | |
end | |
# GET /statuses/new | |
def new | |
@status = Status.new | |
end | |
# GET /statuses/1/edit | |
def edit | |
end | |
# POST /statuses | |
# POST /statuses.json | |
def create | |
@status = Status.new(status_params) | |
respond_to do |format| | |
if @status.save | |
format.html { redirect_to @status, notice: 'Status was successfully created.' } | |
format.json { render action: 'show', status: :created, location: @status } | |
else | |
format.html { render action: 'new' } | |
format.json { render json: @status.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PATCH/PUT /statuses/1 | |
# PATCH/PUT /statuses/1.json | |
def update | |
respond_to do |format| | |
if @status.update(status_params) | |
format.html { redirect_to @status, notice: 'Status was successfully updated.' } | |
format.json { head :no_content } | |
else | |
format.html { render action: 'edit' } | |
format.json { render json: @status.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /statuses/1 | |
# DELETE /statuses/1.json | |
def destroy | |
@status.destroy | |
respond_to do |format| | |
format.html { redirect_to statuses_url } | |
format.json { head :no_content } | |
end | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_status | |
@status = Status.find(params[:id]) | |
end | |
# Never trust parameters from the scary internet, only allow the white list through. | |
def status_params | |
params.require(:status).permit(:content) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment