Skip to content

Instantly share code, notes, and snippets.

@raisen
Created June 10, 2013 03:01
Show Gist options
  • Save raisen/5746266 to your computer and use it in GitHub Desktop.
Save raisen/5746266 to your computer and use it in GitHub Desktop.
Controller:
def update
@pet = current_user.pets.find(params[:id])
end
View:
<%= simple_form_for(@pet, :html => {:class => 'form-horizontal'}) do |f| %>
<%= f.input :name %>
<%= f.association :pet_type, :as => :radio_buttons, :item_wrapper_class => 'inline' %>
<%= f.input :birth_date, :start_year => 1900, :end_year => Time.now.year %>
<%= f.button :submit %>
<% end %>
Model:
class Pet < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
attr_accessible :name, :user_id, :birth_date, :slug, :pet_type_id
belongs_to :user
belongs_to :pet_type
belongs_to :breed_type_1, :class_name => 'Breed'
belongs_to :breed_type_2, :class_name => 'Breed'
has_many :albums
accepts_nested_attributes_for :albums
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment