floriankappert/linkApp1 — Issue #1: links_controller.rb lacks funktionality by adding only new domains 
Author: floriankappert
Created: 2011-12-13 21:53:05+00:00
State: open

def create
@link = Link.new(params[:link])

require 'uri'
host = URI.parse(@link.url).host

hostname = Domain.where(:host => @link.host).first
if( hostname == nil)
hostname = Domain.new(:host => host)
hostname.save
end
@link.domain = hostname

respond_to do |format|
if @link.save
format.html { redirect_to @link, :notice => 'Link was successfully created.' }
format.json { render :json => @link, :status => :created, :location => @link }
else
format.html { render :action => "new" }
format.json { render :json => @link.errors, :status => :unprocessable_entity }
end
end
end