diff options
Diffstat (limited to 'guides/code/getting_started/app')
19 files changed, 120 insertions, 120 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 %> | 
