Skip to content

Instantly share code, notes, and snippets.

@justinleveck
Last active December 18, 2015 07:09
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 justinleveck/5744501 to your computer and use it in GitHub Desktop.
Save justinleveck/5744501 to your computer and use it in GitHub Desktop.
#models / concerns / create_shout.rb
module Concerns
module CreateShout
extend ActiveSupport::Concern
def create
content = build_content
shout = current_user.shouts.build(content: content)
shout.save
if shout.save
redirect_to dashboard_path
else
flash.alert = "Could not shout"
redirect_to dashboard_path
end
end
end
end
class PhotoShoutsController < ApplicationController
include Concerns::CreateShout
private
def build_content
PhotoShout.new(photo_shout_parameters)
end
def photo_shout_parameters
params.require(:photo_shout).permit(:image)
end
end
class TextShoutsController < ApplicationController
include Concerns::CreateShout
private
def build_content
TextShout.new(text_shout_parameters)
end
def text_shout_parameters
params.require(:text_shout).permit(:body)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment