Skip to content

Instantly share code, notes, and snippets.

@fuzzylizard
Last active August 29, 2015 14:03
Show Gist options
  • Save fuzzylizard/df51f9bd85b3558f5d2c to your computer and use it in GitHub Desktop.
Save fuzzylizard/df51f9bd85b3558f5d2c to your computer and use it in GitHub Desktop.
# add column to article model
class AddActiveToArticles< ActiveRecord::Migration
def change
add_column :articles, :active, :boolean
end
end
# now we need to modify our destroy method on our ArticleController
class ArticlesController < ApplicationController
def destroy
article = Article.find(params[:id])
article.update_attribute(:active, false)
redirect_to articles_path
end
end
# We now need a scope so that we are only getting active articles
class Article < ActiveRecord::Base
scope active, -> { where(active: true) }
end
# We now modify our index method in the ArticleController
def index
@articles = Article.active
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment