Skip to content

Instantly share code, notes, and snippets.

@getnashty
Created July 27, 2015 04:21
Show Gist options
  • Save getnashty/0b3793ec42c3a9900bc7 to your computer and use it in GitHub Desktop.
Save getnashty/0b3793ec42c3a9900bc7 to your computer and use it in GitHub Desktop.
def create
if params[:tags]
params[:tags].each do |tag|
@discussion.discussion_tags.create!(
taggable_id: tag['taggable_id'],
taggable_type: tag['taggable_type'].singularize.capitalize,
position: @discussion.discussion_tags.count + 1
)
end
if @discussion.save
render json: @discussion, status: 200
else
render json: { errors: @discussion.errors.full_messages }, status: 422
end
else
if @discussion.save
render json: @discussion, status: 200
else
render json: { errors: @discussion.errors.full_messages }, status: 422
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment