Skip to content

Instantly share code, notes, and snippets.

@supwr
supwr / city.rb
Last active August 29, 2015 14:06
class City < ActiveRecord::Base
# attr_accessible :title, :body
def self.load_cities
workbook = Spreadsheet.open('public/city_list.xls')
worksheet = workbook.worksheet(0)
row_index = 0
class CreateCities < ActiveRecord::Migration
def change
create_table :cities,:id => false do |t|
t.integer :id
t.string :nm
t.decimal :lat
t.decimal :lon
t.string :countryCode
t.timestamps
end
<%= form_for @medico, :url=>{:action => 'create'} do |f|%>
<%=f.text_field :nome%>
<br>
<%=f.fields_for :clinicas do |c|%>
<%= c.text_field :endereco %>
<% end %>
<%=f.submit%>
<% end %>
class MedicosController < ApplicationController
def index
render :text => 'Index'
end
def new
@medico = Medico.new
@medico.clinicas.build
end
class Clinica < ActiveRecord::Base
attr_accessible :ativo, :endereco, :medico_id
belongs_to :medico
end
class Medico < ActiveRecord::Base
attr_accessible :ativo, :nome, :clinicas_attributes
has_many :clinicas
accepts_nested_attributes_for :clinicas
end