Last active
January 1, 2016 04:09
-
-
Save czepluch/8090251 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
class PostsController < ApplicationController | |
before_filter :authenticate_user! | |
def new | |
@post = Post.new | |
end | |
def create | |
@user = User.find(params[:user_id]) | |
@post = @user.posts.create(params[:post].permit(:title, :description, :location)) | |
redirect_to user_path(@user) | |
end | |
def destroy | |
@user = User.find(params[:user_id]) | |
@post = @user.post.find(params[:id]) | |
@post.destroy | |
redirect_to user_path(@user) | |
end | |
# Might not be needed anymore. Leaving it for reference | |
#def create | |
#@post = Post.new(post_params) | |
#if @post.save | |
#redirect_to @post | |
#else | |
#render 'new' | |
#end | |
#end | |
def show | |
@post = Post.find(params[:id]) | |
end | |
def index | |
@posts = Post.all | |
end | |
def edit | |
@post = Post.find(params[:id]) | |
end | |
def update | |
@post = Post.find(params[:id]) | |
if @post.update(params[:post].permit(:title, :description, :location)) | |
redirect_to @post | |
else | |
render 'edit' | |
end | |
end | |
private | |
def post_params | |
params.require(:post).permit(:title, :description, :location) | |
end | |
end | |
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
class UsersController < ApplicationController | |
def show | |
@user = User.find(params[:id]) | |
end | |
def index | |
@users = User.all | |
end | |
# this is just a long shot at a solution | |
def all | |
@posts = Post.all | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment