Skip to content

Instantly share code, notes, and snippets.

@eri-b
Last active September 13, 2019 22:48
Show Gist options
  • Select an option

  • Save eri-b/cb1cb16e5e9c6472f2810957de9ed705 to your computer and use it in GitHub Desktop.

Select an option

Save eri-b/cb1cb16e5e9c6472f2810957de9ed705 to your computer and use it in GitHub Desktop.
class SitesController < ApplicationController
before_action :find_site, only: [:show]
def show
if @site.nil?
@site = Site.new(name: @slug)
if @site.save
flash.now[:notice] = "Your site is ready. Hi #{@slug} :)"
else
redirect_to main_path("faq"), alert: "Site not saved. Letter, numbers, and dashes accepted."
end
end
@feed = @site.posts.order("created_at DESC")
end
private
def find_site
@slug = params[:id].downcase
@site = Site.find_by(name: @slug)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment