Rails: how to save into two tables from one form? - ruby-on-rails

I have to insert some values into another table during sign up. This is what I have tried so far.
The two tables are employees and organizations. This is the form that I am currently using:
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), :html => {:id => "example-advanced-form"}) do |f| %>
<h3>Account</h3>
<fieldset>
<legend>Account Information</legend>
<%= f.label :email %><br>
<%= f.text_field :email, :id => "email-2", :class => "required email" %>
<%= f.label :password %><br>
<%= f.password_field :password, :id => "password-2", :class => "required" %>
<%= f.label :password_confirmation %><br>
<%= f.password_field :password_confirmation, :name => "confirm", :id => "confirm-2", :class => "required" %>
<p>(*) Mandatory</p>
</fieldset>
<h3>Profile</h3>
<fieldset>
<legend>Profile Information</legend>
<div class="container-fluid">
<div class="row">
<div class="col-lg-6">
<%= f.label :first_name %><br>
<%= f.text_field :first_name, :id => "name-2", :class => "required" %>
<%= f.label :middle_name %><br>
<%= f.text_field :middle_name, :id => "surname-2", :class => "required" %>
<%= f.label :last_name %><br>
<%= f.text_field :last_name, :id => "surname-2", :class => "required" %>
<label>Designation</label><br>
<select class="required">
<option value="Developer">Developer</option>
<option value="Tester">Tester</option>
<option value="Manager">Manager</option>
<option value="Other">Other</option>
</select>
<br>
<%= f.fields_for :organisation do |o| %>
<%= o.label :org_name %><br>
<%= o.text_field :org_name, :id => "name-2", :class => "required" %>
<label>organisation Business Type</label><br>
<select class="required">
<option value="Business">Business</option>
<option value="Finance">Finance</option>
<option value="IT">IT</option>
<option value="Other">Other</option>
</select><br>
</div>
<div class="col-lg-6">
<label>Number Of Employees</label><br>
<select class="required">
<option value="0-10">0-10</option>
<option value="10-50">10-50</option>
<option value="50-100">50-100</option>
<option value="100-500">100-500</option>
<option value="500-1000">500-1000</option>
<option value="1000 above">1000 above</option>
</select><br>
<%= o.label :address %><br>
<%= o.text_field :address, :id => "address-2", :class => "required" %>
<%= o.label :city %><br>
<%= o.text_field :city, :class => "required" %>
<%= o.label :state %><br>
<%= o.text_field :state, :class => "required" %>
<%= o.label :country %><br>
<%= o.text_field :country, :class => "required" %>
<%= o.label :email_id %><br>
<%= o.text_field :email_id, :id => "email-2", :class => "required email" %>
<% end %>
</div>
</div>
</div>
</fieldset>
<h3>Finish</h3>
<fieldset>
<legend>Terms and Conditions</legend>
<p>We have sent you a mail for Activation of your Account. Kindly Activate your through the mail. If you haven't received any mail, please click </p>
<%= link_to "here" %>
</fieldset>
<% end %>
The form items within below block
<%= f.fields_for :organisation do |o| %>
<% end %>
are not visible in the browser. And also the values are not stored in the database.
Here are the models and view controllers.
class EmployeesController < ApplicationController
before_action :authenticate_employee!
def index
#employees = Employee.all
end
def new
#employee = Employee.new
#employee.build_organisation
end
def edit
#employee = Employee.find(params[:id])
end
def create
#employee = Employee.new(employee_params)
if #employee.save
flash[:notice] = "Employee was successfully created"
redirect_to employees_path
else
flash[:notice] = "Employee was not created"
end
end
def update
#employee = Employee.find(params[:id])
if #employee.update(employee_params)
flash[:notice] = "Employee was successfully updated"
redirect_to employees_path
else
render 'new'
end
end
def destroy
#employee = Employee.find(params[:id])
#employee.destroy
redirect_to employees_path
end
private
def employee_params
params.require(:employee).permit(:employee_id, :org_id, :role_id, :first_name, :last_name, :middle_name, :dob, :gender, :email_id, :blood_group, :join_date, :left_date, :left_reason, :referred_by, :job_code, :department_code, :encrypted_password, :is_admin, :is_activated, :remarks, :status, :created_by, :updated_by,organisation_attributes: [:org_name,:country,:state,:city,:address,:email_id])
end
end
class OrganisationsController < ApplicationController
def index
#organisations = Organisation.all
end
def show
#org = Organisation.find(params[:id])
#clients = Client.where(org_id: #org.org_id)
end
end
class Employee < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :tasks
belongs_to :organisation
belongs_to :role
accepts_nested_attributes_for :organisation
validates :first_name, presence: true, length: { minimum: 5 }
validates :last_name, presence: true, length: { minimum: 5 }
end
class Organisation < ApplicationRecord
has_many :clients
has_many :employees
end

Related

Rails 4, updating nested polymorphic resource

I have set up polymorphic resource using accepts_nested_attributes_for but for some reason whenever I try to update, instead of just updating the current record, it just create a new one instead. Can anyone tell me what the problem is? Thanks.
vendors_controller.rb
class VendorsController < ApplicationController
before_action :authenticate_user! #check if user logged in
before_action :set_vendor, only: [:show, :edit, :update, :destroy]
def index
#vendors = current_company.vendors
end
def new
#vendor = current_company.vendors.build
#vendor.addresses.build
end
def create
#vendor = current_company.vendors.build(vendor_params)
if #vendor.save
flash[:notice] = 'New Vendor Added'
redirect_to vendors_url
else
flash[:error] = 'Could not save vendor information. Please try again.'
render 'new'
end
end
def show
end
def edit
##vendor = Vendor.find(params[:id])
##vendor.addresses.find_or_initialize_by(addressable_id: #vendor.id, addressable_type: 'Vendor')
end
def update
##vendor = Vendor.find(params[:id])
if #vendor.update(vendor_params)
flash[:notice] = 'Vendor Updated'
redirect_to vendors_path
else
flash[:error] = 'Could not save vendor information. Please try again.'
render 'edit'
end
end
def destroy
#Vendor.find(params[:id]).destroy
#vendor.destroy
flash[:notice] = "Asset deleted"
redirect_to vendors_url
end
private
def vendor_params
params.require(:vendor).permit(:name, :vendorID, :contact, :email, :phone, :image, :remove_image, addresses_attributes: [:street_1, :street_2, :city, :state, :zip] )
end
def set_vendor
#vendor = Vendor.find(params[:id])
end
def current_company
current_user.company
end
end
_form.html.erb
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="card card-block" style="background-color:#f5f5f5">
<%= form_for #vendor do |f| %>
<div class="form-group">
<%= f.label :name, 'Vendor Name' %><br />
<%= f.text_field :name, autofocus: true, required: true, class:'form-control' %>
</div>
<div class="form-group">
<%= f.label :vendorID, 'Vendor ID/Number' %><br />
<%= f.text_field :vendorID, class:'form-control' %>
</div>
<div class="form-group">
<%= f.label :contact, 'Main Contact Person' %><br />
<%= f.text_field :contact, class:'form-control' %>
</div>
<div class="form-group">
<%= f.label :email %><br />
<%= f.email_field :email, class:'form-control' %>
</div>
<div class="form-group">
<%= f.label :phone %><br />
<%= f.phone_field :phone, class:'form-control' %>
</div>
<%= f.fields_for :addresses do |a| %>
<div class="form-group">
<%= a.label :street_1, 'Street' %><br />
<%= a.text_field :street_1, class:'form-control' %>
</div>
<div class="form-group">
<%= a.label :street_2, 'Street 2 (Optional)' %><br />
<%= a.text_field :street_2, class:'form-control' %>
</div>
<div class="form-group">
<%= a.label :city, 'City' %><br />
<%= a.text_field :city, class:'form-control' %>
</div>
<div class="form-group">
<%= a.label :state, 'State' %><br />
<%= a.text_field :state, class:'form-control' %>
</div>
<div class="form-group">
<%= a.label :zip, 'Zip Code' %><br />
<%= a.text_field :zip, class:'form-control' %>
</div>
<% end %>
<div class="actions form-group"><br>
<%= f.submit 'Save Vendor', class: 'btn btn-primary' %>
<%= link_to 'Cancel', :back, class: 'btn btn-default' %>
</div>
<% end %>
</div>
vendor.rb
class Vendor < ActiveRecord::Base
belongs_to :company
has_many :asset
has_many :addresses, as: :addressable, dependent: :destroy
accepts_nested_attributes_for :addresses, reject_if: RejectDeeplyNested.blank?
end
address.rb
class Address < ActiveRecord::Base
belongs_to :addressable, polymorphic: true
end
you need to change your permitted parameters like this
params.require(:vendor).permit(:name, :vendorID, :contact, :email, :phone, :image, :remove_image, addresses_attributes: [:street_1, :street_2, :city, :state, :zip, :id] )
You need to add optional: true to your relationship:
class Address < ApplicationRecord
belongs_to :addressable, polymorphic: true, optional: true
end
Forgot to mention, that optional is available only on Rails > 5

Nested Form for Join Table

I'm attempting to add a nested form into the Devise registration form.
My 3 tables are Users (devise), Languages, and they both are joined in Languages_Users
It signs up the new user, but does not save Languages_Users, but I see that it is passed in the params. A new issue has also arisen - the avatar file is no longer saved. I'm not sure if these are related (if not, don't worry about addressing it).
**UPDATE - Here are my current logs - I now think the issue due to languages_users not receiving user_id
"languages users can't be blank'. In my logs though, it says 'SELECT 1 AS one FROM "languages_users" WHERE ("languages_users"."user_id" IS NULL AND "languages_users"."language_id" = 2) LIMIT 1' Is this an issue with not passing the user_id?
**
User.rb
class User < ActiveRecord::Base
has_many :languages_users
has_many :languages, :through => :languages_users
accepts_nested_attributes_for :languages_users
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
belongs_to :role
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100#" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
validates_presence_of :first_name, :last_name, :location, :nationality, :bio
end
registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :configure_permitted_parameters
def new
build_resource({})
resource.languages_users.build
respond_with self.resource
end
def create
super
end
private
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u|
u.permit(:email, :password, :password_confirmation, :bio, :location, :last_name, :first_name, :nationality, :avatar, languages_user_attributes: [:id, :language_id, :user_id, :level]) }
end
end
in registrations:
new.html.erb
<h2>Sign up</h2>
<%= form_for(resource, as: resource, url: registration_path(resource)) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :first_name %><br />
<%= f.text_field :first_name, autofocus: true %>
</div>
<div class="field">
<%= f.label :last_name %><br />
<%= f.text_field :last_name %>
</div>
<div class="field">
<%= f.label :location %><br />
<%= f.text_field :location %>
</div>
<div class="field">
<%= f.label :nationality %><br/>
<%= f.text_field :nationality %>
</div>
<div class="field">
<%= f.label :bio %><br />
<%= f.text_field :bio %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="form-group">
<%= f.label :avatar, class: 'col-sm-2 control-label' %>
<div class="col-sm-6">
<%= f.file_field "user[avatar]" %>
</div>
</div>
<%= f.fields_for :langauges_user do |lu| %>
<br>
<div class="fields">
<%= lu.collection_select(:language_id, Language.order('language ASC').all, :id, :language) %><br>
<%= lu.hidden_field :level, value: 1 %>
<% end %>
</div>
<br>
<div class="field">
<%= f.label :password %>
<% if #minimum_password_length %>
<em>(<%= #minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
logs:
Started POST "/users" for ::1 at 2016-03-26 13:30:40 -0400
Processing by Users::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"x1F0kXqKN2/uu7S6BLxyBgSatcVWiSOLASEYYJ7ZF0b3d8V8O+FVQAO0yhjTJ2LImI+Xy4j7Rn+SvlYjV07mrA==", "user"=>{"first_name"=>"John", "last_name"=>"Smith", "location"=>"NYC", "nationality"=>"American", "bio"=>"hello", "email"=>"johns#gmail.com", "user"=>{"avatar"=>#<ActionDispatch::Http::UploadedFile:0x007f940b16a4f8 #tempfile=#<Tempfile:/var/folders/cn/l75pvjk9707bj93z_yykb0t40000gn/T/RackMultipart20160326-11607-1fg5ncg.JPG>, #original_filename="IMG_4573.JPG", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"user[user[avatar]]\"; filename=\"IMG_4573.JPG\"\r\nContent-Type: image/jpeg\r\n">}, "langauges_users"=>{"language_id"=>"16", "level"=>"1"}, "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
Unpermitted parameters: user, langauges_users
Still a newb, so please let me know if you'd like me to provide anything further.
Thanks!
You should change languages_user to languages_users
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u|
u.permit(:email, :password, :password_confirmation, :bio, :location, :last_name, :first_name, :nationality, :avatar, languages_users_attributes: [:id, :language_id, :user_id, :level]) }
end
Also in fields_for
<%= f.fields_for :languages_users do |lu| %>

User picture is not saved with devise. Is anything wrong with my devise_registration form or update_form?

I am using carrierwave and minimagick gem to save user for picture uploads in Rails. I have added picture field to the the devise forms and updated the User model to include the mountuploader file.
However, when I try to save, the users attributes are all saved and updated in the database except for the picture.
When I check the User in the console, picture attribute is nil . Any ideas ? My other models save the picture just fine.
Here are my devise forms:
devise_registerations/new
<div class="authform">
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :role => 'form', multipart: true}) do |f| %>
<h3>Sign up</h3>
<%= devise_error_messages! %>
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, :autofocus => true, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :password %>
<%= f.password_field :password, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :country %>
<%= country_select(resource_name, "country")%>
</div>
<div class="form-group">
<%= f.label :description, "Bio" %>
<%= f.text_area :description, class: 'form-control', cols: "30", rows: "10" %>
</div>
Picture: <%= f.file_field :picture %>
<%= f.submit 'Sign up', :class => 'button right' %>
<% end %>
</div>
My edit is similar:
<div class="authform">
<h3>Edit <%= resource_name.to_s.humanize %></h3>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :role => 'form', multipart: true }) do |f| %>
<%= devise_error_messages! %>
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, :autofocus => true, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, class: 'form-control' %>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
</div>
<fieldset>
<p>Leave these fields blank if you don't want to change your password.</p>
<div class="form-group">
<%= f.label :password %>
<%= f.password_field :password, :autocomplete => 'off', class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, class: 'form-control' %>
</div>
</fieldset>
<fieldset>
<p>You must enter your current password to make changes.</p>
<div class="form-group">
<%= f.label :current_password %>
<%= f.password_field :current_password, class: 'form-control' %>
</div>
</fieldset>
Picture: <%= f.file_field :picture %>
<%= f.submit 'Update', :class => 'button right' %>
<% end %>
</div>
<div class="authform">
<h3>Cancel Account</h3>
<p>Unhappy? We'll be sad to see you go.</p>
<%= button_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete, :class => 'button right' %>
</div>
Here is my UsersController :
class UsersController < ApplicationController
before_action :authenticate_user!
before_action :admin_only, :except => :show
def index
#users = User.all
end
def show
#user = User.find(params[:id])
unless (current_user.admin? || current_user == #user)
unless #user == current_user
redirect_to :back, :alert => "Access denied."
end
end
end
def update
#user = User.find(params[:id])
if #user.update_attributes(secure_params)
redirect_to users_path, :notice => "User updated."
else
redirect_to users_path, :alert => "Unable to update user."
end
end
def destroy
user = User.find(params[:id])
user.destroy
redirect_to users_path, :notice => "User deleted."
end
private
def admin_only
unless current_user.admin?
redirect_to :back, :alert => "Access denied."
end
end
def secure_params
params.require(:user).permit(:role, :picture, :name, :email, :password)
end
end
And finally I am including my UserModel:
class User < ActiveRecord::Base
enum role: [:user, :vip, :admin, :manager]
after_initialize :set_default_role, :if => :new_record?
def set_default_role
self.role ||= :user
end
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
mount_uploader :picture, PictureUploader
has_many :projects, dependent: :destroy
end
I think I am in the right path:
https://github.com/carrierwaveuploader/carrierwave/wiki/how-to:-use-carrierwave-with-devise

Rails 4 form_for select tag wont persist when trying to update

So i am trying to implement a dropdown menu in my edit form for users, i used devise, so this edit form is inside my devise/registrations/edit.html.erb file.
first i get and error for undefined method for :optionselect (which seems understandable since i couldn't find this elsewhere other than this select in form_for rails
so this is wrong.
<div class="field">
<%= f.label :role %><br />
<%= f.select :optionselect, User.options %>
</div>
i also had it like this
<div class="field">
<%= f.label :role %><br />
<%= f.select :role, [['Member', 'member'], ['Astronaut', 'astronaut'], ['Candidate', 'candidate']] %>
but no luck. because it wouldn't persist the changes i made when editing the role of the user.
Also the name doesn't persist when trying to update it. maybe that gives us a lead.
models/user.rb
class User < ActiveRecord::Base
has_many :books
has_many :reviews
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
:registerable,
:recoverable,
:rememberable,
:trackable,
:validatable
validates :email, presence: true, uniqueness: true
validates_format_of :email, :with => /\A([^#\s]+)#((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create
validates :password,
:presence => { :on => :create },
:length => { :minimum => 6, :allow_nil => true }
OPTIONS = [
{:role => 'memeber'},
{:role => 'astronaut'},
{:role => 'candidate'}
]
def self.options
OPTIONS.map { |option| option[:role] }
end
end
controllers/users_controller.rb
class UsersController < ApplicationController
def index
binding.pry
#users = User.all
end
def show
#user = User.find(params[:id])
end
def update
#user = User.find(params[:id])
if #user.update!(user_params)
redirect_to :action => 'show', :id => #user
else
render :action => 'edit'
end
end
private
def user_params
params.require(:user).permit(:name, :email, :role)
end
end
devise/registration/edit.html.erb
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name, autofocus: true %>
</div>
<div class="field">
<%= f.label :role %><br />
<%= f.select :optionselect, User.options %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<div class="field">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
<%= link_to "Back", :back %>
Let me know if you need more information
edit.html.erb
<%= f.select(:role, User::USER_OPTIONS) %>
models/user.rb
USER_OPTIONS = ["memeber", "astronaut", "candidate"]

unable to get data from another model using accepts_nested_attributes_for

I have two models User and profile. The profile model has many attributes. I have accessed them in User model using accepts_nested_attributes_for.
Here is my profile.rb model
class Profile < ActiveRecord::Base
attr_accessible :address, :certification, :college, :contact_no, :first_name, :higher_education, :interested_in_learning, :last_name, :profile_pic, :school, :user_id, :would_like_to_teach, :about_video, :about_video_html, :category_name, :category_ids
mount_uploader :profile_pic, ProfimageUploader
has_and_belongs_to_many :categories
belongs_to :user
AutoHtml.add_filter(:image) do |text|
text.gsub(/http:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
%|<img src="#{match}" alt=""/>|
end
end
auto_html_for :about_video do
image
youtube(:width => 170, :height => 100)
link :target => "_blank", :rel => "nofollow"
simple_format
end
def self.search(search)
if search
where('first_name LIKE ?', "%#{search}%")
else
find(:all)
end
end
end
Here is my user.rb model
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
has_one :profile, :dependent => :destroy
accepts_nested_attributes_for :profile
# Setup accessible (or protected) attributes for your model
attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :uid, :provider, :profile_attributes
mount_uploader :profile_pic, ProfimageUploader
acts_as_followable
acts_as_follower
def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
user = User.where(:provider => auth.provider, :uid => auth.uid).first
if user
return user
else
registered_user = User.where(:email => auth.info.email).first
if registered_user
return registered_user
else
user = User.create(name:auth.extra.raw_info.name,
provider:auth.provider,
uid:auth.uid,
email:auth.info.email,
password:Devise.friendly_token[0,20],
)
end
end
end
end
The form in my User edit page is
<% resource.build_profile %>
<%= simple_form_for resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :multipart => true, :class => ".form-horizontal" } do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true, :readonly => true %></div>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, :autocomplete => "off" %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password %></div>
<%= f.fields_for :profile, #user.profile do |prof| %>
<div class="field">
<%= prof.label :first_name %><br />
<%= prof.text_field :first_name %>
</div>
<div class="field">
<%= prof.label :last_name %><br />
<%= prof.text_field :last_name %>
</div>
<div class="field">
<%= prof.label :address %><br />
<%= prof.text_area :address %>
</div>
<div class="field">
<%= prof.label :profile_pic %><br />
<%= prof.file_field :profile_pic %>
</div>
<div class="field">
<%= prof.label :contact_no %><br />
<%= prof.text_field :contact_no %>
</div>
<div class="field">
<%= prof.label :school %><br />
<%= prof.text_field :school %>
</div>
<div class="field">
<%= prof.label :college %><br />
<%= prof.text_field :college %>
</div>
<div class="field">
<%= prof.label :higher_education %><br />
<%= prof.text_field :higher_education %>
</div>
<div class="field">
<%= prof.label :certification %><br />
<%= prof.text_field :certification %>
</div>
<div class="field">
<%= prof.label :about_video %><br />
<%= prof.text_field :about_video %>
</div>
<div class="field">
<%= prof.label :interested_in_learning %><br />
<%= prof.association :categories, :label => "Interested in learning", :wrapper_html => { :id => "iil_multiselect", :class=> "signup_field", :multiselect => true }%>
</div>
<!--<div class="field">
<%# prof.label :interested_in_learning %><br />
<%# prof.text_field :interested_in_learning %>
</div>-->
<div class="field">
<%= prof.label :would_like_to_teach %><br />
<%= prof.text_field :would_like_to_teach %>
</div>
<% end %>
<div><%= f.submit "Save" %></div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %></p>
My profile pic is not seen in the profile/show page What am i doing wrong?

Resources