From f6d5036dd620da48624ce32494f63aa4221b05d5 Mon Sep 17 00:00:00 2001
From: Oscar Del Ben
Date: Fri, 20 Apr 2012 10:43:50 +0200
Subject: Adapt "Getting started guide" code sample
---
.../app/controllers/posts_controller.rb | 76 +---------------------
guides/code/getting_started/app/models/post.rb | 5 +-
.../getting_started/app/views/posts/_form.html.erb | 45 ++++---------
.../getting_started/app/views/posts/new.html.erb | 2 +-
4 files changed, 19 insertions(+), 109 deletions(-)
(limited to 'guides/code/getting_started/app')
diff --git a/guides/code/getting_started/app/controllers/posts_controller.rb b/guides/code/getting_started/app/controllers/posts_controller.rb
index 1581d4eb16..3373443b16 100644
--- a/guides/code/getting_started/app/controllers/posts_controller.rb
+++ b/guides/code/getting_started/app/controllers/posts_controller.rb
@@ -1,84 +1,12 @@
class PostsController < ApplicationController
- http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index
- # GET /posts
- # GET /posts.json
- def index
- @posts = Post.all
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @posts }
- end
- end
-
- # GET /posts/1
- # GET /posts/1.json
- def show
- @post = Post.find(params[:id])
-
- respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @post }
- end
- end
-
- # GET /posts/new
- # GET /posts/new.json
def new
- @post = Post.new
-
- respond_to do |format|
- format.html # new.html.erb
- format.json { render json: @post }
- end
- end
-
- # GET /posts/1/edit
- def edit
- @post = Post.find(params[:id])
end
- # POST /posts
- # POST /posts.json
def create
@post = Post.new(params[:post])
- respond_to do |format|
- if @post.save
- format.html { redirect_to @post, notice: 'Post was successfully created.' }
- format.json { render json: @post, status: :created, location: @post }
- else
- format.html { render action: "new" }
- format.json { render json: @post.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # PUT /posts/1
- # PUT /posts/1.json
- def update
- @post = Post.find(params[:id])
-
- respond_to do |format|
- if @post.update_attributes(params[:post])
- format.html { redirect_to @post, notice: 'Post was successfully updated.' }
- format.json { head :no_content }
- else
- format.html { render action: "edit" }
- format.json { render json: @post.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # DELETE /posts/1
- # DELETE /posts/1.json
- def destroy
- @post = Post.find(params[:id])
- @post.destroy
-
- respond_to do |format|
- format.html { redirect_to posts_url }
- format.json { head :no_content }
- end
+ @post.save
+ redirect_to :action => :index
end
end
diff --git a/guides/code/getting_started/app/models/post.rb b/guides/code/getting_started/app/models/post.rb
index 61c2b5ae44..4b809110b6 100644
--- a/guides/code/getting_started/app/models/post.rb
+++ b/guides/code/getting_started/app/models/post.rb
@@ -1,11 +1,10 @@
class Post < ActiveRecord::Base
- validates :name, :presence => true
validates :title, :presence => true,
:length => { :minimum => 5 }
-
+
has_many :comments, :dependent => :destroy
has_many :tags
-
+
accepts_nested_attributes_for :tags, :allow_destroy => :true,
:reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
end
diff --git a/guides/code/getting_started/app/views/posts/_form.html.erb b/guides/code/getting_started/app/views/posts/_form.html.erb
index e27da7f413..51fa3f4f12 100644
--- a/guides/code/getting_started/app/views/posts/_form.html.erb
+++ b/guides/code/getting_started/app/views/posts/_form.html.erb
@@ -1,32 +1,15 @@
-<% @post.tags.build %>
-<%= form_for(@post) do |post_form| %>
- <% if @post.errors.any? %>
-
-
<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:
-
- <% @post.errors.full_messages.each do |msg| %>
- - <%= msg %>
- <% end %>
-
-
- <% end %>
-
-
- <%= post_form.label :name %>
- <%= post_form.text_field :name %>
-
-
- <%= post_form.label :title %>
- <%= post_form.text_field :title %>
-
-
- <%= post_form.label :content %>
- <%= post_form.text_area :content %>
-
- Tags
- <%= render :partial => 'tags/form',
- :locals => {:form => post_form} %>
-
- <%= post_form.submit %>
-
+<%= form_for :post, :url => { :action => :create } do |f| %>
+
+ <%= f.label :title %>
+ <%= f.text_field :title %>
+
+
+
+ <%= f.label :text %>
+ <%= f.text_area :text %>
+
+
+
+ <%= f.submit %>
+
<% end %>
diff --git a/guides/code/getting_started/app/views/posts/new.html.erb b/guides/code/getting_started/app/views/posts/new.html.erb
index 36ad7421f9..5d6482f880 100644
--- a/guides/code/getting_started/app/views/posts/new.html.erb
+++ b/guides/code/getting_started/app/views/posts/new.html.erb
@@ -2,4 +2,4 @@
<%= render 'form' %>
-<%= link_to 'Back', posts_path %>
+<%#= link_to 'Back', posts_path %>
--
cgit v1.2.3
From dbb4c4ddb601e06fef37f63d644a5297f3292c2a Mon Sep 17 00:00:00 2001
From: Oscar Del Ben
Date: Fri, 20 Apr 2012 10:47:38 +0200
Subject: New Getting started guide wont have tags
---
guides/code/getting_started/app/helpers/posts_helper.rb | 3 ---
guides/code/getting_started/app/models/post.rb | 1 -
guides/code/getting_started/app/models/tag.rb | 3 ---
guides/code/getting_started/app/views/posts/show.html.erb | 7 +------
guides/code/getting_started/app/views/tags/_form.html.erb | 12 ------------
5 files changed, 1 insertion(+), 25 deletions(-)
delete mode 100644 guides/code/getting_started/app/models/tag.rb
delete mode 100644 guides/code/getting_started/app/views/tags/_form.html.erb
(limited to 'guides/code/getting_started/app')
diff --git a/guides/code/getting_started/app/helpers/posts_helper.rb b/guides/code/getting_started/app/helpers/posts_helper.rb
index b6e8e67894..a7b8cec898 100644
--- a/guides/code/getting_started/app/helpers/posts_helper.rb
+++ b/guides/code/getting_started/app/helpers/posts_helper.rb
@@ -1,5 +1,2 @@
module PostsHelper
- def join_tags(post)
- post.tags.map { |t| t.name }.join(", ")
- end
end
diff --git a/guides/code/getting_started/app/models/post.rb b/guides/code/getting_started/app/models/post.rb
index 4b809110b6..e77e607f3f 100644
--- a/guides/code/getting_started/app/models/post.rb
+++ b/guides/code/getting_started/app/models/post.rb
@@ -3,7 +3,6 @@ class Post < ActiveRecord::Base
:length => { :minimum => 5 }
has_many :comments, :dependent => :destroy
- has_many :tags
accepts_nested_attributes_for :tags, :allow_destroy => :true,
:reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
diff --git a/guides/code/getting_started/app/models/tag.rb b/guides/code/getting_started/app/models/tag.rb
deleted file mode 100644
index 30992e8ba9..0000000000
--- a/guides/code/getting_started/app/models/tag.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-class Tag < ActiveRecord::Base
- belongs_to :post
-end
diff --git a/guides/code/getting_started/app/views/posts/show.html.erb b/guides/code/getting_started/app/views/posts/show.html.erb
index da78a9527b..3445fd8779 100644
--- a/guides/code/getting_started/app/views/posts/show.html.erb
+++ b/guides/code/getting_started/app/views/posts/show.html.erb
@@ -14,12 +14,7 @@
Content:
<%= @post.content %>
-
-
- Tags:
- <%= join_tags(@post) %>
-
-
+
Comments
<%= render @post.comments %>
diff --git a/guides/code/getting_started/app/views/tags/_form.html.erb b/guides/code/getting_started/app/views/tags/_form.html.erb
deleted file mode 100644
index 7e424b0e20..0000000000
--- a/guides/code/getting_started/app/views/tags/_form.html.erb
+++ /dev/null
@@ -1,12 +0,0 @@
-<%= form.fields_for :tags do |tag_form| %>
-
- <%= tag_form.label :name, 'Tag:' %>
- <%= tag_form.text_field :name %>
-
- <% unless tag_form.object.nil? || tag_form.object.new_record? %>
-
- <%= tag_form.label :_destroy, 'Remove:' %>
- <%= tag_form.check_box :_destroy %>
-
- <% end %>
-<% end %>
--
cgit v1.2.3
From 2e2afc0ac64190261df4b05428afddea96c8628c Mon Sep 17 00:00:00 2001
From: Oscar Del Ben
Date: Fri, 20 Apr 2012 12:06:47 +0200
Subject: Add show action in getting started guide
---
.../app/controllers/posts_controller.rb | 7 +++++-
guides/code/getting_started/app/models/post.rb | 3 ---
.../getting_started/app/views/posts/show.html.erb | 25 ++++------------------
3 files changed, 10 insertions(+), 25 deletions(-)
(limited to 'guides/code/getting_started/app')
diff --git a/guides/code/getting_started/app/controllers/posts_controller.rb b/guides/code/getting_started/app/controllers/posts_controller.rb
index 3373443b16..f9181f98c6 100644
--- a/guides/code/getting_started/app/controllers/posts_controller.rb
+++ b/guides/code/getting_started/app/controllers/posts_controller.rb
@@ -1,5 +1,10 @@
class PostsController < ApplicationController
+
+ def show
+ @post = Post.find(params[:id])
+ end
+
def new
end
@@ -7,6 +12,6 @@ class PostsController < ApplicationController
@post = Post.new(params[:post])
@post.save
- redirect_to :action => :index
+ redirect_to :action => :show, :id => @post.id
end
end
diff --git a/guides/code/getting_started/app/models/post.rb b/guides/code/getting_started/app/models/post.rb
index e77e607f3f..21387340b0 100644
--- a/guides/code/getting_started/app/models/post.rb
+++ b/guides/code/getting_started/app/models/post.rb
@@ -3,7 +3,4 @@ class Post < ActiveRecord::Base
:length => { :minimum => 5 }
has_many :comments, :dependent => :destroy
-
- accepts_nested_attributes_for :tags, :allow_destroy => :true,
- :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
end
diff --git a/guides/code/getting_started/app/views/posts/show.html.erb b/guides/code/getting_started/app/views/posts/show.html.erb
index 3445fd8779..6207babdf0 100644
--- a/guides/code/getting_started/app/views/posts/show.html.erb
+++ b/guides/code/getting_started/app/views/posts/show.html.erb
@@ -1,26 +1,9 @@
-<%= notice %>
-
- Name:
- <%= @post.name %>
-
-
-
- Title:
+ Title:
<%= @post.title %>
-
+
- Content:
- <%= @post.content %>
+ Text:
+ <%= @post.text %>
-
-Comments
-<%= render @post.comments %>
-
-Add a comment:
-<%= render "comments/form" %>
-
-
-<%= link_to 'Edit Post', edit_post_path(@post) %> |
-<%= link_to 'Back to Posts', posts_path %> |
--
cgit v1.2.3
From e7e72aa253d9cb3bef786a955794986d1f3ff871 Mon Sep 17 00:00:00 2001
From: Oscar Del Ben
Date: Fri, 20 Apr 2012 12:53:18 +0200
Subject: Add index and links section to Getting started guide
---
.../getting_started/app/controllers/home_controller.rb | 2 +-
.../app/controllers/posts_controller.rb | 3 +++
guides/code/getting_started/app/helpers/home_helper.rb | 2 +-
.../code/getting_started/app/views/home/index.html.erb | 2 --
.../getting_started/app/views/posts/index.html.erb | 18 +++++-------------
.../code/getting_started/app/views/posts/new.html.erb | 2 +-
.../code/getting_started/app/views/posts/show.html.erb | 2 ++
.../getting_started/app/views/welcome/index.html.erb | 2 ++
8 files changed, 15 insertions(+), 18 deletions(-)
delete mode 100644 guides/code/getting_started/app/views/home/index.html.erb
create mode 100644 guides/code/getting_started/app/views/welcome/index.html.erb
(limited to 'guides/code/getting_started/app')
diff --git a/guides/code/getting_started/app/controllers/home_controller.rb b/guides/code/getting_started/app/controllers/home_controller.rb
index 6cc31c1ca3..309b70441e 100644
--- a/guides/code/getting_started/app/controllers/home_controller.rb
+++ b/guides/code/getting_started/app/controllers/home_controller.rb
@@ -1,4 +1,4 @@
-class HomeController < ApplicationController
+class WelcomeController < ApplicationController
def index
end
diff --git a/guides/code/getting_started/app/controllers/posts_controller.rb b/guides/code/getting_started/app/controllers/posts_controller.rb
index f9181f98c6..e4d83dd279 100644
--- a/guides/code/getting_started/app/controllers/posts_controller.rb
+++ b/guides/code/getting_started/app/controllers/posts_controller.rb
@@ -1,5 +1,8 @@
class PostsController < ApplicationController
+ def index
+ @posts = Post.all
+ end
def show
@post = Post.find(params[:id])
diff --git a/guides/code/getting_started/app/helpers/home_helper.rb b/guides/code/getting_started/app/helpers/home_helper.rb
index 23de56ac60..eeead45fc9 100644
--- a/guides/code/getting_started/app/helpers/home_helper.rb
+++ b/guides/code/getting_started/app/helpers/home_helper.rb
@@ -1,2 +1,2 @@
-module HomeHelper
+module WelcomeHelper
end
diff --git a/guides/code/getting_started/app/views/home/index.html.erb b/guides/code/getting_started/app/views/home/index.html.erb
deleted file mode 100644
index bb4f3dcd1f..0000000000
--- a/guides/code/getting_started/app/views/home/index.html.erb
+++ /dev/null
@@ -1,2 +0,0 @@
-Hello, Rails!
-<%= link_to "My Blog", posts_path %>
diff --git a/guides/code/getting_started/app/views/posts/index.html.erb b/guides/code/getting_started/app/views/posts/index.html.erb
index 45dee1b25f..455a74b17f 100644
--- a/guides/code/getting_started/app/views/posts/index.html.erb
+++ b/guides/code/getting_started/app/views/posts/index.html.erb
@@ -1,27 +1,19 @@
Listing posts
+<%= link_to 'New post', :action => :new %>
+
- Name |
Title |
- Content |
- |
- |
+ Text |
|
<% @posts.each do |post| %>
- <%= post.name %> |
<%= post.title %> |
- <%= post.content %> |
- <%= link_to 'Show', post %> |
- <%= link_to 'Edit', edit_post_path(post) %> |
- <%= link_to 'Destroy', post, confirm: 'Are you sure?', method: :delete %> |
+ <%= post.text %> |
+ <%= link_to 'Show', :action => :show, :id => post.id %>
|
<% end %>
-
-
-
-<%= link_to 'New Post', new_post_path %>
diff --git a/guides/code/getting_started/app/views/posts/new.html.erb b/guides/code/getting_started/app/views/posts/new.html.erb
index 5d6482f880..ce9523a721 100644
--- a/guides/code/getting_started/app/views/posts/new.html.erb
+++ b/guides/code/getting_started/app/views/posts/new.html.erb
@@ -2,4 +2,4 @@
<%= render 'form' %>
-<%#= link_to 'Back', posts_path %>
+<%= link_to 'Back', :action => :index %>
diff --git a/guides/code/getting_started/app/views/posts/show.html.erb b/guides/code/getting_started/app/views/posts/show.html.erb
index 6207babdf0..a79fadfe4c 100644
--- a/guides/code/getting_started/app/views/posts/show.html.erb
+++ b/guides/code/getting_started/app/views/posts/show.html.erb
@@ -7,3 +7,5 @@
Text:
<%= @post.text %>
+
+<%= link_to 'Back', :action => :index %>
diff --git a/guides/code/getting_started/app/views/welcome/index.html.erb b/guides/code/getting_started/app/views/welcome/index.html.erb
new file mode 100644
index 0000000000..e04680ea7e
--- /dev/null
+++ b/guides/code/getting_started/app/views/welcome/index.html.erb
@@ -0,0 +1,2 @@
+Hello, Rails!
+<%= link_to "My Blog", :controller => "posts" %>
--
cgit v1.2.3
From 504ba12e8cd256b08a43f8ee56c6e2b0272ce6cc Mon Sep 17 00:00:00 2001
From: Oscar Del Ben
Date: Sat, 21 Apr 2012 12:01:33 +0200
Subject: Add model validation section to Getting Started guide
---
.../app/assets/javascripts/comments.js.coffee | 3 --
.../app/assets/javascripts/home.js.coffee | 3 --
.../app/assets/javascripts/posts.js.coffee | 3 --
.../app/assets/stylesheets/comments.css.scss | 3 --
.../app/assets/stylesheets/home.css.scss | 3 --
.../app/assets/stylesheets/posts.css.scss | 3 --
.../app/assets/stylesheets/scaffolds.css.scss | 56 ----------------------
.../app/controllers/posts_controller.rb | 7 ++-
8 files changed, 5 insertions(+), 76 deletions(-)
delete mode 100644 guides/code/getting_started/app/assets/javascripts/comments.js.coffee
delete mode 100644 guides/code/getting_started/app/assets/javascripts/home.js.coffee
delete mode 100644 guides/code/getting_started/app/assets/javascripts/posts.js.coffee
delete mode 100644 guides/code/getting_started/app/assets/stylesheets/comments.css.scss
delete mode 100644 guides/code/getting_started/app/assets/stylesheets/home.css.scss
delete mode 100644 guides/code/getting_started/app/assets/stylesheets/posts.css.scss
delete mode 100644 guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss
(limited to 'guides/code/getting_started/app')
diff --git a/guides/code/getting_started/app/assets/javascripts/comments.js.coffee b/guides/code/getting_started/app/assets/javascripts/comments.js.coffee
deleted file mode 100644
index 761567942f..0000000000
--- a/guides/code/getting_started/app/assets/javascripts/comments.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# 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/
diff --git a/guides/code/getting_started/app/assets/javascripts/home.js.coffee b/guides/code/getting_started/app/assets/javascripts/home.js.coffee
deleted file mode 100644
index 761567942f..0000000000
--- a/guides/code/getting_started/app/assets/javascripts/home.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# 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/
diff --git a/guides/code/getting_started/app/assets/javascripts/posts.js.coffee b/guides/code/getting_started/app/assets/javascripts/posts.js.coffee
deleted file mode 100644
index 761567942f..0000000000
--- a/guides/code/getting_started/app/assets/javascripts/posts.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# 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/
diff --git a/guides/code/getting_started/app/assets/stylesheets/comments.css.scss b/guides/code/getting_started/app/assets/stylesheets/comments.css.scss
deleted file mode 100644
index e730912783..0000000000
--- a/guides/code/getting_started/app/assets/stylesheets/comments.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the Comments controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/guides/code/getting_started/app/assets/stylesheets/home.css.scss b/guides/code/getting_started/app/assets/stylesheets/home.css.scss
deleted file mode 100644
index f0ddc6846a..0000000000
--- a/guides/code/getting_started/app/assets/stylesheets/home.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the home controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/guides/code/getting_started/app/assets/stylesheets/posts.css.scss b/guides/code/getting_started/app/assets/stylesheets/posts.css.scss
deleted file mode 100644
index ed4dfd10f2..0000000000
--- a/guides/code/getting_started/app/assets/stylesheets/posts.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the Posts controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss b/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss
deleted file mode 100644
index 05188f08ed..0000000000
--- a/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss
+++ /dev/null
@@ -1,56 +0,0 @@
-body {
- background-color: #fff;
- color: #333;
- font-family: verdana, arial, helvetica, sans-serif;
- font-size: 13px;
- line-height: 18px; }
-
-p, ol, ul, td {
- font-family: verdana, arial, helvetica, sans-serif;
- font-size: 13px;
- line-height: 18px; }
-
-pre {
- background-color: #eee;
- padding: 10px;
- font-size: 11px; }
-
-a {
- color: #000;
- &:visited {
- color: #666; }
- &:hover {
- color: #fff;
- background-color: #000; } }
-
-div {
- &.field, &.actions {
- margin-bottom: 10px; } }
-
-#notice {
- color: green; }
-
-.field_with_errors {
- padding: 2px;
- background-color: red;
- display: table; }
-
-#error_explanation {
- width: 450px;
- border: 2px solid red;
- padding: 7px;
- padding-bottom: 0;
- margin-bottom: 20px;
- background-color: #f0f0f0;
- h2 {
- text-align: left;
- font-weight: bold;
- padding: 5px 5px 5px 15px;
- font-size: 12px;
- margin: -7px;
- margin-bottom: 0px;
- background-color: #c00;
- color: #fff; }
- ul li {
- font-size: 12px;
- list-style: square; } }
diff --git a/guides/code/getting_started/app/controllers/posts_controller.rb b/guides/code/getting_started/app/controllers/posts_controller.rb
index e4d83dd279..2ad69a9bcf 100644
--- a/guides/code/getting_started/app/controllers/posts_controller.rb
+++ b/guides/code/getting_started/app/controllers/posts_controller.rb
@@ -14,7 +14,10 @@ class PostsController < ApplicationController
def create
@post = Post.new(params[:post])
- @post.save
- redirect_to :action => :show, :id => @post.id
+ if @post.save
+ redirect_to :action => :show, :id => @post.id
+ else
+ render 'new'
+ end
end
end
--
cgit v1.2.3
From 3da2b530aff28d4ea0272e36578188bb6869cbcc Mon Sep 17 00:00:00 2001
From: Oscar Del Ben
Date: Sat, 21 Apr 2012 12:17:51 +0200
Subject: Add validation code to getting started guide and improve validation
section
---
.../code/getting_started/app/controllers/posts_controller.rb | 1 +
guides/code/getting_started/app/views/posts/_form.html.erb | 10 ++++++++++
2 files changed, 11 insertions(+)
(limited to 'guides/code/getting_started/app')
diff --git a/guides/code/getting_started/app/controllers/posts_controller.rb b/guides/code/getting_started/app/controllers/posts_controller.rb
index 2ad69a9bcf..947cd2a767 100644
--- a/guides/code/getting_started/app/controllers/posts_controller.rb
+++ b/guides/code/getting_started/app/controllers/posts_controller.rb
@@ -9,6 +9,7 @@ class PostsController < ApplicationController
end
def new
+ @post = Post.new
end
def create
diff --git a/guides/code/getting_started/app/views/posts/_form.html.erb b/guides/code/getting_started/app/views/posts/_form.html.erb
index 51fa3f4f12..18cb29f335 100644
--- a/guides/code/getting_started/app/views/posts/_form.html.erb
+++ b/guides/code/getting_started/app/views/posts/_form.html.erb
@@ -1,4 +1,14 @@
<%= form_for :post, :url => { :action => :create } do |f| %>
+ <% if @post.errors.any? %>
+
+
<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:
+
+ <% @post.errors.full_messages.each do |msg| %>
+ - <%= msg %>
+ <% end %>
+
+
+ <% end %>
<%= f.label :title %>
<%= f.text_field :title %>
--
cgit v1.2.3
From 5acb345a86584e3c9c4b5a81c4499c767393c89a Mon Sep 17 00:00:00 2001
From: Oscar Del Ben
Date: Tue, 24 Apr 2012 12:30:24 +0200
Subject: Fix some code in getting started guide
---
guides/code/getting_started/app/helpers/home_helper.rb | 2 --
guides/code/getting_started/app/helpers/welcome_helper.rb | 2 ++
2 files changed, 2 insertions(+), 2 deletions(-)
delete mode 100644 guides/code/getting_started/app/helpers/home_helper.rb
create mode 100644 guides/code/getting_started/app/helpers/welcome_helper.rb
(limited to 'guides/code/getting_started/app')
diff --git a/guides/code/getting_started/app/helpers/home_helper.rb b/guides/code/getting_started/app/helpers/home_helper.rb
deleted file mode 100644
index eeead45fc9..0000000000
--- a/guides/code/getting_started/app/helpers/home_helper.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-module WelcomeHelper
-end
diff --git a/guides/code/getting_started/app/helpers/welcome_helper.rb b/guides/code/getting_started/app/helpers/welcome_helper.rb
new file mode 100644
index 0000000000..eeead45fc9
--- /dev/null
+++ b/guides/code/getting_started/app/helpers/welcome_helper.rb
@@ -0,0 +1,2 @@
+module WelcomeHelper
+end
--
cgit v1.2.3
From f0de7172a6e1a52bf122578954d805a36a488d27 Mon Sep 17 00:00:00 2001
From: Oscar Del Ben
Date: Tue, 24 Apr 2012 14:21:07 +0200
Subject: Add update post section to getting started guide
---
.../getting_started/app/controllers/posts_controller.rb | 14 ++++++++++++++
guides/code/getting_started/app/views/posts/_form.html.erb | 2 +-
guides/code/getting_started/app/views/posts/edit.html.erb | 3 +--
guides/code/getting_started/app/views/posts/index.html.erb | 2 ++
guides/code/getting_started/app/views/posts/show.html.erb | 1 +
5 files changed, 19 insertions(+), 3 deletions(-)
(limited to 'guides/code/getting_started/app')
diff --git a/guides/code/getting_started/app/controllers/posts_controller.rb b/guides/code/getting_started/app/controllers/posts_controller.rb
index 947cd2a767..fc71e9b4e8 100644
--- a/guides/code/getting_started/app/controllers/posts_controller.rb
+++ b/guides/code/getting_started/app/controllers/posts_controller.rb
@@ -21,4 +21,18 @@ class PostsController < ApplicationController
render 'new'
end
end
+
+ def edit
+ @post = Post.find(params[:id])
+ end
+
+ def update
+ @post = Post.find(params[:id])
+
+ if @post.update_attributes(params[:post])
+ redirect_to :action => :show, :id => @post.id
+ else
+ render 'edit'
+ end
+ end
end
diff --git a/guides/code/getting_started/app/views/posts/_form.html.erb b/guides/code/getting_started/app/views/posts/_form.html.erb
index 18cb29f335..46ec257b91 100644
--- a/guides/code/getting_started/app/views/posts/_form.html.erb
+++ b/guides/code/getting_started/app/views/posts/_form.html.erb
@@ -1,4 +1,4 @@
-<%= form_for :post, :url => { :action => :create } do |f| %>
+<%= form_for :post, :url => { :action => :update, :id => @post.id }, :method => :put do |f| %>
<% if @post.errors.any? %>
<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:
diff --git a/guides/code/getting_started/app/views/posts/edit.html.erb b/guides/code/getting_started/app/views/posts/edit.html.erb
index 720580236b..911a48569d 100644
--- a/guides/code/getting_started/app/views/posts/edit.html.erb
+++ b/guides/code/getting_started/app/views/posts/edit.html.erb
@@ -2,5 +2,4 @@
<%= render 'form' %>
-<%= link_to 'Show', @post %> |
-<%= link_to 'Back', posts_path %>
+<%= link_to 'Back', :action => :index %>
diff --git a/guides/code/getting_started/app/views/posts/index.html.erb b/guides/code/getting_started/app/views/posts/index.html.erb
index 455a74b17f..3ba7091c15 100644
--- a/guides/code/getting_started/app/views/posts/index.html.erb
+++ b/guides/code/getting_started/app/views/posts/index.html.erb
@@ -7,6 +7,7 @@
Title |
Text |
|
+
|
<% @posts.each do |post| %>
@@ -14,6 +15,7 @@
<%= post.title %> |
<%= post.text %> |
<%= link_to 'Show', :action => :show, :id => post.id %>
+ | <%= link_to 'Edit', :action => :edit, :id => post.id %>
<% end %>
diff --git a/guides/code/getting_started/app/views/posts/show.html.erb b/guides/code/getting_started/app/views/posts/show.html.erb
index a79fadfe4c..aea28cd5a2 100644
--- a/guides/code/getting_started/app/views/posts/show.html.erb
+++ b/guides/code/getting_started/app/views/posts/show.html.erb
@@ -9,3 +9,4 @@
<%= link_to 'Back', :action => :index %>
+| <%= link_to 'Edit', :action => :edit, :id => @post.id %>
--
cgit v1.2.3
From ee4e7125a61c703332a8d591a0aee917ba828e62 Mon Sep 17 00:00:00 2001
From: Oscar Del Ben
Date: Wed, 25 Apr 2012 15:43:10 +0200
Subject: Add partials section to getting started guide
---
guides/code/getting_started/app/views/posts/_form.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'guides/code/getting_started/app')
diff --git a/guides/code/getting_started/app/views/posts/_form.html.erb b/guides/code/getting_started/app/views/posts/_form.html.erb
index 46ec257b91..b35ea2f237 100644
--- a/guides/code/getting_started/app/views/posts/_form.html.erb
+++ b/guides/code/getting_started/app/views/posts/_form.html.erb
@@ -1,4 +1,4 @@
-<%= form_for :post, :url => { :action => :update, :id => @post.id }, :method => :put do |f| %>
+<%= form_for @post do |f| %>
<% if @post.errors.any? %>
<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:
--
cgit v1.2.3
From f4447607f20c420d9c341b19064c07d5b7aa6cee Mon Sep 17 00:00:00 2001
From: Oscar Del Ben
Date: Fri, 27 Apr 2012 14:21:02 +0200
Subject: Add delete post section to Getting Started guide
---
guides/code/getting_started/app/controllers/posts_controller.rb | 7 +++++++
guides/code/getting_started/app/views/posts/index.html.erb | 2 ++
2 files changed, 9 insertions(+)
(limited to 'guides/code/getting_started/app')
diff --git a/guides/code/getting_started/app/controllers/posts_controller.rb b/guides/code/getting_started/app/controllers/posts_controller.rb
index fc71e9b4e8..85d2c1de47 100644
--- a/guides/code/getting_started/app/controllers/posts_controller.rb
+++ b/guides/code/getting_started/app/controllers/posts_controller.rb
@@ -35,4 +35,11 @@ class PostsController < ApplicationController
render 'edit'
end
end
+
+ def destroy
+ @post = Post.find(params[:id])
+ @post.destroy
+
+ redirect_to :action => :index
+ end
end
diff --git a/guides/code/getting_started/app/views/posts/index.html.erb b/guides/code/getting_started/app/views/posts/index.html.erb
index 3ba7091c15..7b72720d50 100644
--- a/guides/code/getting_started/app/views/posts/index.html.erb
+++ b/guides/code/getting_started/app/views/posts/index.html.erb
@@ -8,6 +8,7 @@
Text |
|
|
+ |
<% @posts.each do |post| %>
@@ -16,6 +17,7 @@
<%= post.text %> |
<%= link_to 'Show', :action => :show, :id => post.id %>
| <%= link_to 'Edit', :action => :edit, :id => post.id %>
+ | <%= link_to 'Destroy', { :action => :destroy, :id => post.id }, :method => :delete, :confirm => 'Are you sure?' %>
<% end %>
--
cgit v1.2.3
| |