Skip to content

Instantly share code, notes, and snippets.

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 elliott-king/f88d207f351017b75ad924b1251d71d2 to your computer and use it in GitHub Desktop.
Save elliott-king/f88d207f351017b75ad924b1251d71d2 to your computer and use it in GitHub Desktop.
Controller to create new user and attach Active Storage file ID
class UsersController < ApplicationController
def create
resume = params[:pdf]
params = user_params.except(:pdf)
user = User.create!(params)
user.resume.attach(resume) if resume.present? && !!user
render json: user.as_json(root: false, methods: :resume_url).except('updated_at')
end
private
def user_params
params.permit(:email, :first_name, :last_name, :pdf)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment