Skip to content

Commit

Permalink
Article create options was done
Browse files Browse the repository at this point in the history
 - Article controller was added
 - Article model and migration files were created
 - New article form was created
  • Loading branch information
tayfunoziserikan committed Aug 17, 2014
1 parent c9fcf02 commit 7bb54e5
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 0 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/
23 changes: 23 additions & 0 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class ArticlesController < ApplicationController

def new
end


def create

@article = Article.new(article_params)

@article.save

redirect_to @article

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
2 changes: 2 additions & 0 deletions app/models/article.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Article < ActiveRecord::Base
end
17 changes: 17 additions & 0 deletions app/views/articles/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<h1>New Article</h1>

<%= form_for :article, url: articles_path do |f| %>
<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 %>
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 7bb54e5

Please sign in to comment.