Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Meu controlador
- class HostingController < ApplicationController
- def index
- end
- def step_one
- @customer = Customer.new
- end
- def save_step_one
- if request.post?
- unless params[:domain].blank?
- @msg = Customer.check_domain(params[:domain])
- session[:domain] = params[:domain]
- end
- else
- redirect_to :action => "step_one"
- end
- end
- def step_two
- session[:customer] = @customer
- end
- def save_step_two
- @customer = Customer.new(params[:customer])
- if @customer.save
- render :action => "index"
- else
- render :action => "step_two"
- end
- end
- end
- #Modelo de dados
- class Customer < ActiveRecord::Base
- require 'universal_ruby_whois'
- require 'brazilian-rails'
- validates_presence_of :cnpj, :name, :state, :province, :city
- usar_como_cnpj :cnpj
- def self.check_domain(domain)
- @t = Whois.find(domain)
- if @t.nil? || @t.blank?
- @message = "Dominio invalido"
- elsif @t.available? == false
- @message = "Dominio ja registrado"
- else
- @message = "Dominio liberado" if @t.available? == true
- end
- @message
- end
- end
- #Minha view já integrada ao layout padrão
- <% form_tag('javascript:void(0)') do %>
- <label for="domain">Domínio: </label><%= text_field_tag 'domain' %>
- <% end %>
- <%= observe_field :domain,
- :frequency => 3,
- :loading => "Element.show('spinner')",
- :complete => "Element.hide('spinner')",
- :url => { :action => 'save_step_one', :only_path => false},
- :with => "'domain=' + encodeURIComponent(value)"
- %>
- <%= image_tag 'ajax-loader.gif', :id => 'spinner', :style => "display:none" %>
- <div id="results"></div>
- #save_step_one.rjs -> ajax
- page.replace_html 'results', :partial => "domain" unless @msg == "Dominio invalido"
- page.replace_html 'results', "Informe um domínio válido" if params[:domain].blank? || @msg == "Dominio invalido"
Add Comment
Please, Sign In to add comment