Last active
August 29, 2015 14:03
-
-
Save fuzzylizard/df51f9bd85b3558f5d2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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