forked from LYK2014-Ruby-Rails/blog-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/article' into develop
- Loading branch information
Showing
18 changed files
with
206 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the articles controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class ArticlesController < ApplicationController | ||
|
||
def index | ||
@articles = Article.all | ||
end | ||
|
||
def show | ||
@article = Article.find(params[:id]) | ||
end | ||
|
||
def edit | ||
@article = Article.find(params[:id]) | ||
end | ||
|
||
def update | ||
@article = Article.find(params[:id]) | ||
|
||
if @article.update(article_params) | ||
redirect_to @article | ||
else | ||
render 'edit' | ||
end | ||
end | ||
|
||
def new | ||
@article = Article.new | ||
end | ||
|
||
def create | ||
|
||
@article = Article.new(article_params) | ||
|
||
if @article.save | ||
redirect_to @article | ||
else | ||
render 'new' | ||
end | ||
|
||
end | ||
|
||
def destroy | ||
|
||
@article = Article.find(params[:id]) | ||
@article.destroy | ||
|
||
redirect_to articles_path | ||
end | ||
|
||
private | ||
|
||
def article_params | ||
params.require(:article).permit(:title, :text) | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ArticlesHelper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Article < ActiveRecord::Base | ||
validates :title, presence: true, | ||
length: { minimum: 5 } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<%= form_for @article do |f| %> | ||
|
||
<% if @article.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@article.errors.count, "error") %> prohibited | ||
this article from being saved:</h2> | ||
<ul> | ||
<% @article.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<p> | ||
<%= f.label :title %><br> | ||
<%= f.text_field :title %> | ||
</p> | ||
|
||
<p> | ||
<%= f.label :text %><br> | ||
<%= f.text_area :text %> | ||
</p> | ||
|
||
<p> | ||
<%= f.submit %> | ||
</p> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>Editing article</h1> | ||
|
||
<%= render 'form' %> | ||
|
||
<%= link_to 'Back', articles_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<h1>Listing Articles</h1> | ||
|
||
<%= link_to 'New article', new_article_path %> | ||
|
||
<table> | ||
<tr> | ||
<th>Title</th> | ||
<th>Text</th> | ||
<th colspan="3">Options</th> | ||
</tr> | ||
|
||
<% @articles.each do |article| %> | ||
<tr> | ||
<td><%= article.title %></td> | ||
<td><%= article.text %></td> | ||
<td><%= link_to 'Show', article_path(article) %></td> | ||
<td><%= link_to 'Edit', edit_article_path(article) %></td> | ||
<td><%= link_to 'Destroy', article_path(article), | ||
method: :delete, data: { confirm: 'Are you sure?' } %></td> | ||
</tr> | ||
<% end %> | ||
</table> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>New Article</h1> | ||
|
||
<%= render 'form' %> | ||
|
||
<%= link_to 'Back', articles_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<h1>Article Details</h1> | ||
|
||
<p> | ||
<strong>Title:</strong> | ||
<%= @article.title %> | ||
</p> | ||
|
||
<p> | ||
<strong>Text:</strong> | ||
<%= @article.text %> | ||
</p> | ||
|
||
<%= link_to 'Back', articles_path %> | ||
| <%= link_to 'Edit', edit_article_path(@article) %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<h1>Welcome#index</h1> | ||
<p>Find me in app/views/welcome/index.html.erb</p> | ||
<h1>Welcome our LYK2014 Blog</h1> | ||
|
||
<%= link_to 'LYK2014 Blog', controller: 'articles' %> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateArticles < ActiveRecord::Migration | ||
def change | ||
create_table :articles do |t| | ||
t.string :title | ||
t.text :text | ||
|
||
t.timestamps | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# encoding: UTF-8 | ||
# This file is auto-generated from the current state of the database. Instead | ||
# of editing this file, please use the migrations feature of Active Record to | ||
# incrementally modify your database, and then regenerate this schema definition. | ||
# | ||
# Note that this schema.rb definition is the authoritative source for your | ||
# database schema. If you need to create the application database on another | ||
# system, you should be using db:schema:load, not running all the migrations | ||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
# you'll amass, the slower it'll run and the greater likelihood for issues). | ||
# | ||
# It's strongly recommended that you check this file into your version control system. | ||
|
||
ActiveRecord::Schema.define(version: 20140817122829) do | ||
|
||
create_table "articles", force: true do |t| | ||
t.string "title" | ||
t.text "text" | ||
t.datetime "created_at" | ||
t.datetime "updated_at" | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class ArticlesControllerTest < ActionController::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
one: | ||
title: MyString | ||
text: MyText | ||
|
||
two: | ||
title: MyString | ||
text: MyText |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'test_helper' | ||
|
||
class ArticlesHelperTest < ActionView::TestCase | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class ArticleTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |