Sha256: 4591cd3e9771886d0150b8d196c2047e689901e070c9ef32137e2e9e7e031084

Contents?: true

Size: 837 Bytes

Versions: 6

Compression:

Stored size: 837 Bytes

Contents

class PostsController < ApplicationController
  def index
    @posts = Post.all
  end

  def new
    @post_form = PostForm.new
  end

  def create
    @post_form = PostForm.new(params[:post])

    if @post_form.valid?
      Post.create(@post_form.attributes)
      flash[:notice] = "Successfully created"
      redirect_to :posts
    else
      flash[:alert] = "Validation errors"
      render "new"
    end
  end

  def edit
    @post = Post.find(params[:id])
    @post_form = PostForm.new(@post)
  end

  def update
    @post = Post.find(params[:id])
    @post_form = PostForm.new(params[:post])

    if @post_form.valid?
      @post.update_attributes(@post_form.attributes)
      flash[:notice] = "Successfully updated"
      redirect_to :posts
    else
      flash[:alert] = "Validation errors"
      render "edit"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
funky_form-0.2.1 test/dummy/app/controllers/posts_controller.rb
funky_form-0.2.0 test/dummy/app/controllers/posts_controller.rb
funky_form-0.1.3 test/dummy/app/controllers/posts_controller.rb
funky_form-0.1.2 test/dummy/app/controllers/posts_controller.rb
funky_form-0.1.1 test/dummy/app/controllers/posts_controller.rb
funky_form-0.1.0 test/dummy/app/controllers/posts_controller.rb