Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

git@github.com:varid007/hello.git

  • Loading branch information...
commit 3541a17897fab96713d1fb0a9c82a3d0f57c0707 1 parent 6cda7dd
@varid007 authored
Showing with 239 additions and 15 deletions.
  1. +3 −0  belajar/app/assets/javascripts/articles.js.coffee
  2. +3 −0  belajar/app/assets/stylesheets/articles.css.scss
  3. +50 −0 belajar/app/controllers/articles_controller.rb
  4. +7 −0 belajar/app/controllers/articles_controller.rb~
  5. +6 −6 belajar/app/controllers/welcome_controller.rb
  6. +9 −1 belajar/app/controllers/welcome_controller.rb~
  7. +2 −0  belajar/app/helpers/articles_helper.rb
  8. +3 −1 belajar/app/models/countrie.rb
  9. +14 −0 belajar/app/models/countrie.rb~
  10. +2 −2 belajar/app/models/user.rb
  11. +5 −0 belajar/app/models/user.rb~
  12. +22 −0 belajar/app/views/articles/edit.html.erb
  13. +28 −0 belajar/app/views/articles/index.html.erb
  14. +11 −0 belajar/app/views/articles/index.html.erb~
  15. +16 −0 belajar/app/views/articles/new.html.erb
  16. +8 −0 belajar/app/views/articles/show.html.erb
  17. +1 −0  belajar/app/views/welcome/hello_instance.html.erb
  18. +1 −0  belajar/app/views/welcome/hello_instance.html.erb~
  19. +2 −1  belajar/config/routes.rb
  20. +2 −1  belajar/config/routes.rb~
  21. +13 −0 belajar/db/migrate/20120501103804_add_touser.rb~
  22. +7 −0 belajar/db/migrate/20120503040257_add_to_user.rb
  23. +7 −0 belajar/db/migrate/20120503040257_add_to_user.rb~
  24. +4 −1 belajar/db/schema.rb
  25. +1 −1  belajar/db/seeds.rb
  26. +1 −1  belajar/db/seeds.rb~
  27. +7 −0 belajar/test/functional/articles_controller_test.rb
  28. +4 −0 belajar/test/unit/helpers/articles_helper_test.rb
View
3  belajar/app/assets/javascripts/articles.js.coffee
@@ -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://jashkenas.github.com/coffee-script/
View
3  belajar/app/assets/stylesheets/articles.css.scss
@@ -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/
View
50 belajar/app/controllers/articles_controller.rb
@@ -0,0 +1,50 @@
+class ArticlesController < ApplicationController
+
+ def index
+ @articles = Article.all
+ end
+
+ def create
+ @article = Article.new(params[:id])
+ if @article.save
+
+ redirect_to articles_path
+ else
+ render :new
+ end
+ end
+
+ def new
+ @article = Article.new
+
+ end
+
+ def edit
+ @article = Article.find_by_id(params[:id])
+ end
+
+ def show
+ @article = Article.find_by_id(params[:id])
+
+ end
+
+ def update
+ @article = Article.find(params[:id])
+
+ if @article.update_attributes(params[:article])
+
+ redirect_to articles_path
+ else
+ flash[:notice] = 'User was Error.'
+ render :edit
+ end
+
+ end
+
+ def destroy
+ @article = Article.find_by_id(params[:id])
+ @article.destroy
+ redirect_to articles_path
+ end
+
+end
View
7 belajar/app/controllers/articles_controller.rb~
@@ -0,0 +1,7 @@
+class ArticlesController < ApplicationController
+
+ def index
+ @articles = Articles.all
+ end
+
+end
View
12 belajar/app/controllers/welcome_controller.rb
@@ -1,12 +1,12 @@
class WelcomeController < ApplicationController
-def test
-end
+ def test
+ end
-def hello_instance
+ def hello_instance
@welcome_instance="hello world dari instance variable"
-end
+ end
-def hello_render
+ def hello_render
render:text=>"welcome from render"
-end
+ end
end
View
10 belajar/app/controllers/welcome_controller.rb~
@@ -1,4 +1,12 @@
class WelcomeController < ApplicationController
-def hello
+def test
+end
+
+def hello_instance
+ @welcome_instance="hello world dari instance variable"
+end
+
+def hello_render
+ render:text=>"welcome from render"
end
end
View
2  belajar/app/helpers/articles_helper.rb
@@ -0,0 +1,2 @@
+module ArticlesHelper
+end
View
4 belajar/app/models/countrie.rb
@@ -1,7 +1,7 @@
class Countrie < ActiveRecord::Base
belongs_to :user
- validate :valid_id
+
def valid_id
self.errors[:code]<< "Harus id, usa atau frc" unless code =="id" || code == "usa" || code == "frc"
end
@@ -9,6 +9,8 @@ def valid_id
validates :name, :presence => true,
:length => {:minimum => 1, :maximum => 15},
:format => {:with => /[a-zA-Z\s]+$/}
+
+ validate :valid_id
end
View
14 belajar/app/models/countrie.rb~
@@ -0,0 +1,14 @@
+class Countrie < ActiveRecord::Base
+ belongs_to :user
+
+ validate :valid_id
+ def valid_id
+ self.errors[:code]<< "Harus id, usa atau frc" unless code =="id" || code == "usa" || code == "frc"
+ end
+
+ validates :name, :presence => true,
+ :length => {:minimum => 1, :maximum => 15},
+ :format => {:with => /[a-zA-Z\s]+$/}
+end
+
+
View
4 belajar/app/models/user.rb
@@ -5,8 +5,8 @@ class User < ActiveRecord::Base
has_many :shared_articles,
:class_name => "Article",
- :foreign_key => "user_id"
- :"title like '%share%'"
+ :foreign_key => "user_id",
+ :condition =>"title like '%share%'"
def show_full_name
View
5 belajar/app/models/user.rb~
@@ -3,6 +3,11 @@ class User < ActiveRecord::Base
has_many :articles
has_many :countries
+ has_many :shared_articles,
+ :class_name => "Article",
+ :foreign_key => "user_id"
+ :"title like '%share%'"
+
def show_full_name
"#{self.first_name} #{self.last_name}"
View
22 belajar/app/views/articles/edit.html.erb
@@ -0,0 +1,22 @@
+<%= form_for @article do |f| %>
+
+<% if @article.errors.any? %>
+ <div id="errorExplanation">
+ <h2>
+ <%= pluralize(@article.errors.count, "error") %> Please title or body was Error:
+ </h2>
+ <ul>
+ <% @article.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+<% end %>
+
+
+ Title : <br/><%= f.text_field :title %> <br/>
+ Article :<br/> <%= f.text_area :body %><br/>
+ Rating : <%= f.text_field :rating %><br/>
+ <%= f.submit "Submit" %>
+ <%= link_to "Back to Index",articles_path%>
+ <% end %>
View
28 belajar/app/views/articles/index.html.erb
@@ -0,0 +1,28 @@
+<html>
+<head>
+ <title>Ruby On Rails</title>
+</head>
+
+<body>
+<%= link_to "Add Article",new_article_path %>
+ <table>
+ <tr>
+ <th>Title</th>
+ <th>Body</th>
+ <th>Rating</th>
+ <th>Manage</th>
+ </tr>
+
+ <% @articles.each do |article| %>
+ <tr>
+ <td><%= article.title %></td>
+ <td><%= article.body %></td>
+ <td><%= article.rating %></td>
+ <td><%= link_to "show", article_path(article.id) %> | <%= link_to "edit", edit_article_path(article.id) %>| <%= link_to "delete", article_path(article.id),method: :delete %></td>
+ </tr>
+ <% end %>
+
+ </table>
+</body>
+
+</html>
View
11 belajar/app/views/articles/index.html.erb~
@@ -0,0 +1,11 @@
+<html>
+<head>
+ <title>Ruby On Rails</title>
+</head>
+<body>
+ <ul>
+ <% Articles.each do |p|%>
+ <li><%= p.article %></li>
+ </ul>
+</body>
+</html>
View
16 belajar/app/views/articles/new.html.erb
@@ -0,0 +1,16 @@
+<html>
+<head>
+ <title>Ruby On Rails</title>
+</head>
+
+<body>
+ <%= form_for @article do |f| %>
+ Title : <br/><%= f.text_field :title %> <br/>
+ Article :<br/> <%= f.text_area :body %><br/>
+ Rating : <%= f.text_field :rating %><br/>
+ <%= f.submit "Submit" %>
+ <% end %>
+ <%= link_to "Back to Index",articles_path%>
+</body>
+
+</html>
View
8 belajar/app/views/articles/show.html.erb
@@ -0,0 +1,8 @@
+<html>
+<body>
+<%= @article.title %>
+<%= @article.body %>
+<%= @article.rating %>
+<%= link_to "back",articles_path %>
+</body>
+</html>
View
1  belajar/app/views/welcome/hello_instance.html.erb
@@ -0,0 +1 @@
+<%= @welcome_instance %>
View
1  belajar/app/views/welcome/hello_instance.html.erb~
@@ -0,0 +1 @@
+<%=@welcome_instance%>
View
3  belajar/config/routes.rb
@@ -54,5 +54,6 @@
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
- match ':controller(/:action(/:id(.:format)))'
+ #match ':controller(/:action(/:id(.:format)))'
+ resources :articles
end
View
3  belajar/config/routes.rb~
@@ -54,5 +54,6 @@ Belajar::Application.routes.draw do
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
- match ':controller(/:action(/:id(.:format)))'
+ #match ':controller(/:action(/:id(.:format)))'
+ resourses :articles
end
View
13 belajar/db/migrate/20120501103804_add_touser.rb~
@@ -0,0 +1,13 @@
+class AddTouser < ActiveRecord::Migration
+ def up
+ add_column :users, :address, :string
+ add_column :users, :age, :integer
+ add_column :users, :birthday, :string
+ end
+ def down
+ remove_column :users, :address, :string
+ remove_column :users, :age, :integer
+ remove_column :users, :birthday, :string
+
+ end
+end
View
7 belajar/db/migrate/20120503040257_add_to_user.rb
@@ -0,0 +1,7 @@
+class AddToUser < ActiveRecord::Migration
+ def change
+ add_column :users, :address, :string
+ add_column :users, :age, :integer
+ add_column :users, :birthday, :string
+ end
+end
View
7 belajar/db/migrate/20120503040257_add_to_user.rb~
@@ -0,0 +1,7 @@
+class AddToUser < ActiveRecord::Migration
+ def up
+ end
+
+ def down
+ end
+end
View
5 belajar/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120502062857) do
+ActiveRecord::Schema.define(:version => 20120503040257) do
create_table "articles", :force => true do |t|
t.string "title"
@@ -62,6 +62,9 @@
t.string "username"
t.datetime "created_at"
t.datetime "updated_at"
+ t.string "address"
+ t.integer "age"
+ t.string "birthday"
end
create_table "welcomes", :force => true do |t|
View
2  belajar/db/seeds.rb
@@ -6,7 +6,7 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
-countries = Countries.create([{:code => "JKT1", :name => "Jakarta"},
+countries = Countrie.create([{:code => "JKT1", :name => "Jakarta"},
{:code => "JKT2", :name => "Bandung"},
{:code => "JKT3", :name => "Padang"},
{:code => "JKT4", :name => "Jambi"},
View
2  belajar/db/seeds.rb~
@@ -6,7 +6,7 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
-countries = Counties.create([{:code => "JKT1", :name => "Jakarta"},
+countries = Countries.create([{:code => "JKT1", :name => "Jakarta"},
{:code => "JKT2", :name => "Bandung"},
{:code => "JKT3", :name => "Padang"},
{:code => "JKT4", :name => "Jambi"},
View
7 belajar/test/functional/articles_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ArticlesControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
4 belajar/test/unit/helpers/articles_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ArticlesHelperTest < ActionView::TestCase
+end
Please sign in to comment.
Something went wrong with that request. Please try again.