Skip to content

Instantly share code, notes, and snippets.

class Medico < ActiveRecord::Base
attr_accessible :ativo, :nome, :clinicas_attributes
has_many :clinicas
accepts_nested_attributes_for :clinicas
end
class Clinica < ActiveRecord::Base
attr_accessible :ativo, :endereco, :medico_id
belongs_to :medico
end
class MedicosController < ApplicationController
def index
render :text => 'Index'
end
def new
@medico = Medico.new
@medico.clinicas.build
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 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
@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
@supwr
supwr / countdown.php
Created April 13, 2015 12:24
Print 100 to 1. Using code starting with "for($i=0", without anything before "for($i=0" and without using any loop inside this "for" code block. Read this challenge as a part of an article written on the site DevBattles.com(http://www.devbattles.com/en/sand/post-1038-Why+can%27t+programmers+program)
<?php
for($i=0;$i < 100;$i++){
echo ($i - 100)*(-1)."<br>";
}
?>
import sublime, sublime_plugin
import datetime
import subprocess
import os
class HelloCommand(sublime_plugin.TextCommand):
def run(self, edit):
arquivo = self.view.file_name()
@supwr
supwr / phploc.py
Last active August 29, 2015 14:20
import sublime, sublime_plugin
import datetime
import subprocess
import os
class PhplocCommand(sublime_plugin.TextCommand):
# Class created to consume Sebastian Bergmann's PHPLOC
# from SublimeText
@supwr
supwr / content_home.xml
Created February 3, 2016 16:14
Linear layout com texto, botão
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"