Skip to content

Commit

Permalink
Merge branch 'feature/article' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tayfunoziserikan committed Aug 17, 2014
2 parents c9fcf02 + 3f5a12c commit f26ba5c
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/articles.js.coffee
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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/articles.css.scss
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/
55 changes: 55 additions & 0 deletions app/controllers/articles_controller.rb
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
2 changes: 2 additions & 0 deletions app/helpers/articles_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ArticlesHelper
end
4 changes: 4 additions & 0 deletions app/models/article.rb
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
28 changes: 28 additions & 0 deletions app/views/articles/_form.html.erb
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 %>
5 changes: 5 additions & 0 deletions app/views/articles/edit.html.erb
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 %>
22 changes: 22 additions & 0 deletions app/views/articles/index.html.erb
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>
5 changes: 5 additions & 0 deletions app/views/articles/new.html.erb
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 %>
14 changes: 14 additions & 0 deletions app/views/articles/show.html.erb
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) %>
5 changes: 3 additions & 2 deletions app/views/welcome/index.html.erb
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' %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Rails.application.routes.draw do
get 'welcome/index'

resources :articles

# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20140817122829_create_articles.rb
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
23 changes: 23 additions & 0 deletions db/schema.rb
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
7 changes: 7 additions & 0 deletions test/controllers/articles_controller_test.rb
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
9 changes: 9 additions & 0 deletions test/fixtures/articles.yml
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
4 changes: 4 additions & 0 deletions test/helpers/articles_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'test_helper'

class ArticlesHelperTest < ActionView::TestCase
end
7 changes: 7 additions & 0 deletions test/models/article_test.rb
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

0 comments on commit f26ba5c

Please sign in to comment.