Skip to content

Instantly share code, notes, and snippets.

@brunofonseca
Created March 31, 2015 01:47
Show Gist options
  • Save brunofonseca/bfef87278e3aa849d394 to your computer and use it in GitHub Desktop.
Save brunofonseca/bfef87278e3aa849d394 to your computer and use it in GitHub Desktop.
def create
if user_signed_in?
@url = current_user.urls.new(url_params)
respond_to do |format|
if @url.save
format.html { redirect_to root_path }
format.json { render :show, status: :created, location: @url }
else
format.html { redirect_to root_path }
format.json { render json: @url.errors, status: :unprocessable_entity }
end
end
else
@url = Url.new(url_params)
@url.attributes = {user_id: '0'}
respond_to do |format|
if @url.save
#format.html { redirect_to root_path, notice: 'Link Salvo.' }
format.json { render json: @url.minaddress }
else
format.html { redirect_to root_path, notice: 'Link Invalido' }
format.json { render json: @url.errors }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment