public
Last active

File not assigned

  • Download Gist
photos.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#/model/user.rb
attr_accessible :name, :first_name, :last_name, :email, :password, :password_confirmation, :remember_me,
:provider, :uid, :photos_attributes
 
has_many :photos
accepts_nested_attributes_for :photos
 
#/model/photo.rb
class Photo < ActiveRecord::Base
attr_accessible :id, :photo, :user_id
belongs_to :user
mount_uploader :photo, PhotoUploader
end
 
#/controllers/users_controller.rb
def show
@photos = @user.photos
end
 
def update
@user.photos.build
end
 
#/views/devise/registration/edit.html.erb
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :class => 'form-vertical', :multipart => true }) do |f| %>
<%= f.error_notification %>
...
 
<%= f.fields_for :photos do |p| %>
<%= p.file_field :photo %>
<% end %>
...
 
<% end %>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.