diff options
Diffstat (limited to 'guides/code/getting_started')
30 files changed, 145 insertions, 145 deletions
| diff --git a/guides/code/getting_started/app/assets/javascripts/posts.js.coffee b/guides/code/getting_started/app/assets/javascripts/articles.js.coffee index 24f83d18bb..24f83d18bb 100644 --- a/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +++ b/guides/code/getting_started/app/assets/javascripts/articles.js.coffee diff --git a/guides/code/getting_started/app/assets/stylesheets/posts.css.scss b/guides/code/getting_started/app/assets/stylesheets/articles.css.scss index 1a7e15390c..cca548710d 100644 --- a/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +++ b/guides/code/getting_started/app/assets/stylesheets/articles.css.scss @@ -1,3 +1,3 @@ -// Place all the styles related to the posts controller here. +// 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/ diff --git a/guides/code/getting_started/app/controllers/articles_controller.rb b/guides/code/getting_started/app/controllers/articles_controller.rb new file mode 100644 index 0000000000..275b84e8b7 --- /dev/null +++ b/guides/code/getting_started/app/controllers/articles_controller.rb @@ -0,0 +1,53 @@ +class ArticlesController < ApplicationController + +  http_basic_authenticate_with name: "dhh", password: "secret", except: [:index, :show] + +  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 action: :show, id: @article.id +    else +      render 'edit' +    end +  end + +  def new +    @article = Article.new +  end + +  def create +    @article = Article.new(article_params) + +    if @article.save +      redirect_to action: :show, id: @article.id +    else +      render 'new' +    end +  end + +  def destroy +    @article = Article.find(params[:id]) +    @article.destroy + +    redirect_to action: :index +  end + +  private + +    def article_params +      params.require(:article).permit(:title, :text) +    end +end diff --git a/guides/code/getting_started/app/controllers/comments_controller.rb b/guides/code/getting_started/app/controllers/comments_controller.rb index b2d9bcdf7f..61813b1003 100644 --- a/guides/code/getting_started/app/controllers/comments_controller.rb +++ b/guides/code/getting_started/app/controllers/comments_controller.rb @@ -3,16 +3,16 @@ class CommentsController < ApplicationController    http_basic_authenticate_with name: "dhh", password: "secret", only: :destroy    def create -    @post = Post.find(params[:post_id]) -    @comment = @post.comments.create(comment_params) -    redirect_to post_path(@post) +    @article = Article.find(params[:article_id]) +    @comment = @article.comments.create(comment_params) +    redirect_to article_path(@article)    end    def destroy -    @post = Post.find(params[:post_id]) -    @comment = @post.comments.find(params[:id]) +    @article = Article.find(params[:article_id]) +    @comment = @article.comments.find(params[:id])      @comment.destroy -    redirect_to post_path(@post) +    redirect_to article_path(@article)    end    private diff --git a/guides/code/getting_started/app/controllers/posts_controller.rb b/guides/code/getting_started/app/controllers/posts_controller.rb deleted file mode 100644 index 02689ad67b..0000000000 --- a/guides/code/getting_started/app/controllers/posts_controller.rb +++ /dev/null @@ -1,53 +0,0 @@ -class PostsController < ApplicationController - -  http_basic_authenticate_with name: "dhh", password: "secret", except: [:index, :show] - -  def index -    @posts = Post.all -  end - -  def show -    @post = Post.find(params[:id]) -  end - -  def edit -    @post = Post.find(params[:id]) -  end - -  def update -    @post = Post.find(params[:id]) - -    if @post.update(post_params) -      redirect_to action: :show, id: @post.id -    else -      render 'edit' -    end -  end - -  def new -    @post = Post.new -  end - -  def create -    @post = Post.new(post_params) - -    if @post.save -      redirect_to action: :show, id: @post.id -    else -      render 'new' -    end -  end - -  def destroy -    @post = Post.find(params[:id]) -    @post.destroy - -    redirect_to action: :index -  end - -  private - -    def post_params -      params.require(:post).permit(:title, :text) -    end -end diff --git a/guides/code/getting_started/app/helpers/articles_helper.rb b/guides/code/getting_started/app/helpers/articles_helper.rb new file mode 100644 index 0000000000..2968277595 --- /dev/null +++ b/guides/code/getting_started/app/helpers/articles_helper.rb @@ -0,0 +1,2 @@ +module ArticlesHelper +end diff --git a/guides/code/getting_started/app/helpers/posts_helper.rb b/guides/code/getting_started/app/helpers/posts_helper.rb deleted file mode 100644 index a7b8cec898..0000000000 --- a/guides/code/getting_started/app/helpers/posts_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module PostsHelper -end diff --git a/guides/code/getting_started/app/models/post.rb b/guides/code/getting_started/app/models/article.rb index 64e0d721fd..6fc7888be2 100644 --- a/guides/code/getting_started/app/models/post.rb +++ b/guides/code/getting_started/app/models/article.rb @@ -1,6 +1,6 @@ -class Post < ActiveRecord::Base +class Article < ActiveRecord::Base    has_many :comments, dependent: :destroy -   +    validates :title,      presence: true,      length: { minimum: 5 } diff --git a/guides/code/getting_started/app/models/comment.rb b/guides/code/getting_started/app/models/comment.rb index 4e76c5b5b0..e2646a324f 100644 --- a/guides/code/getting_started/app/models/comment.rb +++ b/guides/code/getting_started/app/models/comment.rb @@ -1,3 +1,3 @@  class Comment < ActiveRecord::Base -  belongs_to :post +  belongs_to :article  end diff --git a/guides/code/getting_started/app/views/posts/_form.html.erb b/guides/code/getting_started/app/views/articles/_form.html.erb index f2f83585e1..87e3353ed2 100644 --- a/guides/code/getting_started/app/views/posts/_form.html.erb +++ b/guides/code/getting_started/app/views/articles/_form.html.erb @@ -1,10 +1,10 @@ -<%= form_for @post do |f| %> -  <% if @post.errors.any? %> +<%= form_for @article do |f| %> +  <% if @article.errors.any? %>    <div id="error_explanation"> -    <h2><%= pluralize(@post.errors.count, "error") %> prohibited -      this post from being saved:</h2> +    <h2><%= pluralize(@article.errors.count, "error") %> prohibited +      this article from being saved:</h2>      <ul> -    <% @post.errors.full_messages.each do |msg| %> +    <% @article.errors.full_messages.each do |msg| %>        <li><%= msg %></li>      <% end %>      </ul> diff --git a/guides/code/getting_started/app/views/posts/edit.html.erb b/guides/code/getting_started/app/views/articles/edit.html.erb index 393e7430d0..14236e2a98 100644 --- a/guides/code/getting_started/app/views/posts/edit.html.erb +++ b/guides/code/getting_started/app/views/articles/edit.html.erb @@ -1,5 +1,5 @@ -<h1>Edit post</h1> -  +<h1>Edit article</h1> +  <%= render 'form' %> -  +  <%= link_to 'Back', action: :index %> diff --git a/guides/code/getting_started/app/views/articles/index.html.erb b/guides/code/getting_started/app/views/articles/index.html.erb new file mode 100644 index 0000000000..80e9c8c60c --- /dev/null +++ b/guides/code/getting_started/app/views/articles/index.html.erb @@ -0,0 +1,21 @@ +<h1>Listing Articles</h1> +<table> +  <tr> +    <th>Title</th> +    <th>Text</th> +    <th></th> +    <th></th> +    <th></th> +  </tr> + +<% @articles.each do |article| %> +  <tr> +    <td><%= article.title %></td> +    <td><%= article.text %></td> +    <td><%= link_to 'Show', action: :show, id: article.id %></td> +    <td><%= link_to 'Edit', action: :edit, id: article.id %></td> +    <td><%= link_to 'Destroy', { action: :destroy, id: article.id }, +                    method: :delete, data: { confirm: 'Are you sure?' } %></td> +  </tr> +<% end %> +</table> diff --git a/guides/code/getting_started/app/views/posts/new.html.erb b/guides/code/getting_started/app/views/articles/new.html.erb index efa81038ec..652b1c9c0b 100644 --- a/guides/code/getting_started/app/views/posts/new.html.erb +++ b/guides/code/getting_started/app/views/articles/new.html.erb @@ -1,5 +1,5 @@ -<h1>New post</h1> -  +<h1>New article</h1> +  <%= render 'form' %> -  +  <%= link_to 'Back', action: :index %> diff --git a/guides/code/getting_started/app/views/articles/show.html.erb b/guides/code/getting_started/app/views/articles/show.html.erb new file mode 100644 index 0000000000..6959c80bdb --- /dev/null +++ b/guides/code/getting_started/app/views/articles/show.html.erb @@ -0,0 +1,18 @@ +<p> +  <strong>Title:</strong> +  <%= @article.title %> +</p> + +<p> +  <strong>Text:</strong> +  <%= @article.text %> +</p> + +<h2>Comments</h2> +<%= render @article.comments %> + +<h2>Add a comment:</h2> +<%= render "comments/form" %> + +<%= link_to 'Edit Article', edit_article_path(@article) %> | +<%= link_to 'Back to Articles', articles_path %> diff --git a/guides/code/getting_started/app/views/comments/_comment.html.erb b/guides/code/getting_started/app/views/comments/_comment.html.erb index 593493339e..f7cbfaebfa 100644 --- a/guides/code/getting_started/app/views/comments/_comment.html.erb +++ b/guides/code/getting_started/app/views/comments/_comment.html.erb @@ -2,14 +2,14 @@    <strong>Commenter:</strong>    <%= comment.commenter %>  </p> -  +  <p>    <strong>Comment:</strong>    <%= comment.body %>  </p>  <p> -  <%= link_to 'Destroy Comment', [comment.post, comment], +  <%= link_to 'Destroy Comment', [comment.article, comment],                 method: :delete,                 data: { confirm: 'Are you sure?' } %>  </p> diff --git a/guides/code/getting_started/app/views/comments/_form.html.erb b/guides/code/getting_started/app/views/comments/_form.html.erb index 00cb3a08f0..5850c41a17 100644 --- a/guides/code/getting_started/app/views/comments/_form.html.erb +++ b/guides/code/getting_started/app/views/comments/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_for([@post, @post.comments.build]) do |f| %> +<%= form_for([@article, @article.comments.build]) do |f| %>    <p>      <%= f.label :commenter %><br />      <%= f.text_field :commenter %> diff --git a/guides/code/getting_started/app/views/posts/index.html.erb b/guides/code/getting_started/app/views/posts/index.html.erb deleted file mode 100644 index 7369f0396f..0000000000 --- a/guides/code/getting_started/app/views/posts/index.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -<h1>Listing Posts</h1> -<table> -  <tr> -    <th>Title</th> -    <th>Text</th> -    <th></th> -    <th></th> -    <th></th> -  </tr> -  -<% @posts.each do |post| %> -  <tr> -    <td><%= post.title %></td> -    <td><%= post.text %></td> -    <td><%= link_to 'Show', action: :show, id: post.id %></td> -    <td><%= link_to 'Edit', action: :edit, id: post.id %></td> -    <td><%= link_to 'Destroy', { action: :destroy, id: post.id }, -                    method: :delete, data: { confirm: 'Are you sure?' } %></td> -  </tr> -<% end %> -</table> diff --git a/guides/code/getting_started/app/views/posts/show.html.erb b/guides/code/getting_started/app/views/posts/show.html.erb deleted file mode 100644 index e99e9edbb3..0000000000 --- a/guides/code/getting_started/app/views/posts/show.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -<p> -  <strong>Title:</strong> -  <%= @post.title %> -</p> -  -<p> -  <strong>Text:</strong> -  <%= @post.text %> -</p> - -<h2>Comments</h2> -<%= render @post.comments %> -  -<h2>Add a comment:</h2> -<%= render "comments/form" %> -  -<%= link_to 'Edit Post', edit_post_path(@post) %> | -<%= link_to 'Back to Posts', posts_path %> diff --git a/guides/code/getting_started/app/views/welcome/index.html.erb b/guides/code/getting_started/app/views/welcome/index.html.erb index 56be8dd3cc..1cabd0d217 100644 --- a/guides/code/getting_started/app/views/welcome/index.html.erb +++ b/guides/code/getting_started/app/views/welcome/index.html.erb @@ -1,4 +1,4 @@  <h1>Hello, Rails!</h1> -<%= link_to "My Blog", controller: "posts" %> -<%= link_to "New Post", new_post_path %> +<%= link_to "My Blog", controller: "articles" %> +<%= link_to "New Article", new_article_path %> diff --git a/guides/code/getting_started/config/environments/production.rb b/guides/code/getting_started/config/environments/production.rb index c8ae858574..60adba903a 100644 --- a/guides/code/getting_started/config/environments/production.rb +++ b/guides/code/getting_started/config/environments/production.rb @@ -16,10 +16,10 @@ Rails.application.configure do    # Enable Rack::Cache to put a simple HTTP cache in front of your application    # Add `rack-cache` to your Gemfile before enabling this. -  # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. +  # For large-scale production use, consider using a caching reverse proxy like NGINX, varnish or squid.    # config.action_dispatch.rack_cache = true -  # Disable Rails's static asset server (Apache or nginx will already do this). +  # Disable Rails's static asset server (Apache or NGINX will already do this).    config.serve_static_assets = false    # Compress JavaScripts and CSS. @@ -36,8 +36,8 @@ Rails.application.configure do    config.assets.version = '1.0'    # Specifies the header that your server uses for sending files. -  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache -  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx +  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache +  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX    # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.    # config.force_ssl = true diff --git a/guides/code/getting_started/config/routes.rb b/guides/code/getting_started/config/routes.rb index 65d273b58d..97abca99b9 100644 --- a/guides/code/getting_started/config/routes.rb +++ b/guides/code/getting_started/config/routes.rb @@ -1,5 +1,5 @@  Rails.application.routes.draw do -  resources :posts do +  resources :articles do      resources :comments    end diff --git a/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb b/guides/code/getting_started/db/migrate/20130122042648_create_articles.rb index 602bef31ab..6bb255e89f 100644 --- a/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +++ b/guides/code/getting_started/db/migrate/20130122042648_create_articles.rb @@ -1,6 +1,6 @@ -class CreatePosts < ActiveRecord::Migration +class CreateArticles < ActiveRecord::Migration    def change -    create_table :posts do |t| +    create_table :articles do |t|        t.string :title        t.text :text diff --git a/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb b/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb index 3e51f9c0f7..1f765839ac 100644 --- a/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +++ b/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb @@ -3,7 +3,7 @@ class CreateComments < ActiveRecord::Migration      create_table :comments do |t|        t.string :commenter        t.text :body -      t.references :post, index: true +      t.references :article, index: true        t.timestamps      end diff --git a/guides/code/getting_started/db/schema.rb b/guides/code/getting_started/db/schema.rb index 101fe712a1..be40f7cb0e 100644 --- a/guides/code/getting_started/db/schema.rb +++ b/guides/code/getting_started/db/schema.rb @@ -13,21 +13,21 @@  ActiveRecord::Schema.define(version: 20130122045842) do -  create_table "comments", force: true do |t| -    t.string   "commenter" -    t.text     "body" -    t.integer  "post_id" +  create_table "articles", force: true do |t| +    t.string   "title" +    t.text     "text"      t.datetime "created_at"      t.datetime "updated_at"    end -  add_index "comments", ["post_id"], name: "index_comments_on_post_id" - -  create_table "posts", force: true do |t| -    t.string   "title" -    t.text     "text" +  create_table "comments", force: true do |t| +    t.string   "commenter" +    t.text     "body" +    t.integer  "article_id"      t.datetime "created_at"      t.datetime "updated_at"    end +  add_index "comments", ["article_id"], name: "index_comments_on_article_id" +  end diff --git a/guides/code/getting_started/test/controllers/posts_controller_test.rb b/guides/code/getting_started/test/controllers/articles_controller_test.rb index 7a6ee4f1db..361aa0f47f 100644 --- a/guides/code/getting_started/test/controllers/posts_controller_test.rb +++ b/guides/code/getting_started/test/controllers/articles_controller_test.rb @@ -1,6 +1,6 @@  require 'test_helper' -class PostsControllerTest < ActionController::TestCase +class ArticlesControllerTest < ActionController::TestCase    # test "the truth" do    #   assert true    # end diff --git a/guides/code/getting_started/test/fixtures/posts.yml b/guides/code/getting_started/test/fixtures/articles.yml index 46b01c3bb4..46b01c3bb4 100644 --- a/guides/code/getting_started/test/fixtures/posts.yml +++ b/guides/code/getting_started/test/fixtures/articles.yml diff --git a/guides/code/getting_started/test/fixtures/comments.yml b/guides/code/getting_started/test/fixtures/comments.yml index 9e409d8a61..05ad26f051 100644 --- a/guides/code/getting_started/test/fixtures/comments.yml +++ b/guides/code/getting_started/test/fixtures/comments.yml @@ -3,9 +3,9 @@  one:    commenter: MyString    body: MyText -  post_id:  +  article_id:  two:    commenter: MyString    body: MyText -  post_id:  +  article_id: diff --git a/guides/code/getting_started/test/helpers/articles_helper_test.rb b/guides/code/getting_started/test/helpers/articles_helper_test.rb new file mode 100644 index 0000000000..b341344067 --- /dev/null +++ b/guides/code/getting_started/test/helpers/articles_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class ArticlesHelperTest < ActionView::TestCase +end diff --git a/guides/code/getting_started/test/helpers/posts_helper_test.rb b/guides/code/getting_started/test/helpers/posts_helper_test.rb deleted file mode 100644 index 48549c2ea1..0000000000 --- a/guides/code/getting_started/test/helpers/posts_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class PostsHelperTest < ActionView::TestCase -end diff --git a/guides/code/getting_started/test/models/post_test.rb b/guides/code/getting_started/test/models/article_test.rb index 6d9d463a71..11c8abe5f4 100644 --- a/guides/code/getting_started/test/models/post_test.rb +++ b/guides/code/getting_started/test/models/article_test.rb @@ -1,6 +1,6 @@  require 'test_helper' -class PostTest < ActiveSupport::TestCase +class ArticleTest < ActiveSupport::TestCase    # test "the truth" do    #   assert true    # end | 
