diff options
author | twinturbo <me@broadcastingadam.com> | 2012-04-28 22:33:11 -0700 |
---|---|---|
committer | twinturbo <me@broadcastingadam.com> | 2012-04-28 22:33:11 -0700 |
commit | d7532c189f26e008fc6ef50336ed5e8168b8221c (patch) | |
tree | 681436aa5d80ed5e4c9a867ccc891eab6852f124 /guides/code/getting_started/app/controllers | |
parent | 2c136ae0543ea53dcb3a3ef9372b216b54d66172 (diff) | |
parent | 6659252d9f0e6d77bee268adf587e03cfeb8f9ad (diff) | |
download | rails-d7532c189f26e008fc6ef50336ed5e8168b8221c.tar.gz rails-d7532c189f26e008fc6ef50336ed5e8168b8221c.tar.bz2 rails-d7532c189f26e008fc6ef50336ed5e8168b8221c.zip |
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'guides/code/getting_started/app/controllers')
-rw-r--r-- | guides/code/getting_started/app/controllers/home_controller.rb | 2 | ||||
-rw-r--r-- | guides/code/getting_started/app/controllers/posts_controller.rb | 67 |
2 files changed, 15 insertions, 54 deletions
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 1581d4eb16..85d2c1de47 100644 --- a/guides/code/getting_started/app/controllers/posts_controller.rb +++ b/guides/code/getting_started/app/controllers/posts_controller.rb @@ -1,84 +1,45 @@ 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 + if @post.save + redirect_to :action => :show, :id => @post.id + else + render 'new' end end - # PUT /posts/1 - # PUT /posts/1.json + def edit + @post = Post.find(params[:id]) + end + 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 + if @post.update_attributes(params[:post]) + redirect_to :action => :show, :id => @post.id + else + render 'edit' 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 + redirect_to :action => :index end end |