Skip to content

Instantly share code, notes, and snippets.

@hackrio1
Created July 30, 2018 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hackrio1/64c0b8aef14d3c488b7a8956315bbaca to your computer and use it in GitHub Desktop.
Save hackrio1/64c0b8aef14d3c488b7a8956315bbaca to your computer and use it in GitHub Desktop.
class ArticlesController < ApplicationController
before_action :set_user
before_action :set_article, only: [:show, :edit, :update, :destroy]
# GET /articles/1
# GET /articles.json
def index
@articles = @users.articles.all
end
# GET /articles/1
# GET /articles/1.json
def show
end
# GET /articles/new
def new
@articles = @users.articles.new
end
# GET /articles/1/edit
def edit
end
# POST /articles
# POST /articles.json
def create
@articles = @users.articles.new(articles_params)
respond_to do |format|
if @article.save
format.html { redirect_to @article, notice: 'Article was succesfully created.' }
format.json { render :show, status: :created, location: @article }
else
format.html { render.new }
format.json { render json: @articles.errors, status: :unprocessable_entity }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment