Last active
September 17, 2019 23:17
-
-
Save eri-b/32a92f51ddbdd268cd82c910666096a4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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_action :editable?, only: [:create] | |
def create | |
@site = Site.find_by(name: params[:post][:site]) | |
@post = @site.posts.build(post_params) | |
if @post.save | |
redirect_to main_path(@post.site.name) | |
else | |
render 'sites/show' | |
end | |
end | |
private | |
def post_params | |
params.require(:post).permit(:body) | |
end | |
# make sure site is editable before creating post (either public or private + unlocked) | |
def editable? | |
@slug = params[:post][:site] | |
@site = Site.find_by(name: @slug) | |
if private? | |
redirect_to main_path(@site.name), notice: 'Site is locked.' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment