Pretty standard update in my opinion, but upon submitting the put request, the attribute is not updated. Here is my relevant model:
class Vendor < ActiveRecord::Base
geocoded_by :address
after_validation :geocode,
:if => lambda{ |obj| obj.address_changed? }
end
My controller methods:
def edit
#vendor = Vendor.find(params[:id])
end
def update
#vendor = Vendor.find(params[:id])
if #vendor.update_attributes(vendor_params)
redirect_to vendors_mgmt_path
else
render 'edit'
end
end
def vendor_params
params.permit(:id, :name, :address, :image, :latitude, :longituded )
end
I see this in the server log after trying to update:
Started PUT "/vendors/1" for 127.0.0.1 at 2013-10-20 20:44:54 -0700
Processing by VendorsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"fTbZVEfckQz4xQzY5xSMQCArrGZqymNsVeyic/PXKcE=", "vendor"=>{"name"=>"Store", "address"=>"1221 E. Main St."}, "commit"=>"Save changes", "id"=>"1"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Vendor Load (0.2ms) SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" = ? LIMIT 1 [["id", "1"]]
Unpermitted parameters: utf8, _method, authenticity_token, vendor, commit
(0.1ms) begin transaction
(0.1ms) commit transaction
Redirected to http://localhost:3000/vendors/mgmt
Completed 302 Found in 10ms (ActiveRecord: 0.6ms)
This confuses me, because the Vendor form looks like so, and has no authenticity token etc.
<h1>Update <%= "#{#vendor.name}" %></h1>
<%= form_for(#vendor) do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :address %>
<%= f.text_field :address %>
<%= f.label :Logo %>
<%= f.file_field :image %>
<%= f.submit "Save changes", class: "btn btn-success" %>
<% end %>
Anyone see any glaring errors? Any help is much appreciated. Thanks in advance!
Rails by default includes certain hidden fields in all forms, such as the authenticity_token, which is present to stop CSRF. (More info here) I would recommend changing the line:
params.permit(:id, :name, :address, :image, :latitude, :longituded )
to:
params.require(:vendor).permit(:id, :name, :address, :image, :latitude, :longituded)
Changing this line in your controller should permit the other parameters that are submitted by the form, not just the ones in the vendor param.
Also, you misspelled "longitude", I'm not sure if that's causing any additional trouble or if it's just a typo in your question instead.
Related
I'm not sure why but I cannot save my form input to the database, and I couldn't find any answer so far :), but it works for creating the posts using the console.
Started POST "/posts" for 127.0.0.1 at 2018-05-23 14:04:32 +0300
Processing by PostsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"B19yVi1jHtg7068SKFbI3tj28THNdfgGYwUSN+e79Vt/o0ivDUl0D4i71PuLKlZf1wxnEJMVnp+GmH/HcxE6cQ==", "post"=>{"category_id"=>"2", "title"=>"asfaf", "content"=>"asfkja", "photo_cache"=>""}, "commit"=>"Create Post"}
Unpermitted parameter: :photo_cache
User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
(0.5ms) BEGIN
Category Load (0.5ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
(0.4ms) ROLLBACK
<%= simple_form_for(#post) do |f| %>
<%= f.collection_select(:category_id, Category.all, :id, :name, {prompt: "Choose a category" }) %><br>
<%= f.label :title %><br>
<%= f.text_field :title, placeholder: "Type the post title here" %><br>
<%= f.label :content %><br>
<%= f.text_area :content, placeholder: "Type the post text here" %><br>
<%= f.input :photo %>
<%= f.input :photo_cache, as: :hidden %><br>
<%= f.submit %>
<% end %>
def new
#post = Post.new
authorize #post
end
def create
#post = Post.new(post_params)
authorize #post
if #post.save
redirect_to #post, notice: "The post was created!"
else
render 'new'
end
end
def post_params
params.require(:post).permit(:title, :content, :category_id, :photo, :user_id)
end
class Post < ApplicationRecord
validates :title, :content, :category_id, presence: true
belongs_to :category
belongs_to :user
mount_uploader :photo, PhotoUploader
end
Console output points the reason - you pass photo_cache parameter while have not permitted it:
Unpermitted parameter: :photo_cache
So, just add :photo_cache to permit list:
params.require(:post).permit(..., :photo_cache)
UPDATE: If Post model belongs to User, it should have foreign key constraint and you must pass user_id parameter to Post.create.
In real apps something like Devise is used for authentication and controller looks like:
class PostsController < ApplicationController
before_action :authenticate_user!
def create
post = current_user.posts.create!(create_params)
# post = Post.new(create_params.merge(user: current_user))
# ...
end
end
Basically what helped is changing the create method
def create
#post = current_user.posts.new(post_params)
authorize #post
if #post.save
redirect_to #post, notice: "The post was created!"
else
render 'new'
end
end
The attachment resume seems to works fine, but i do not have any insert into database (null, null, null , null) and i do not have file uploaded to any folder in my app...
class AddAttachmentCvToUsers < ActiveRecord::Migration
def change
change_table :users do |t|
t.attachment :cv
end
end
end
User model :
attr_accessor :cv
validates_attachment :cv
has_attached_file :cv, :path=>":rails_root/storage/#{Rails.env}#{ENV['RAILS_TEST_NUMBER']}/."
I have also installed carrierwave but still no effects..
Edit:
User Controller (I do not have another controller for attachments) :
class UsersController < ApplicationController
def new
#users = User.new
end
def create
#user = User.new(user_params)
if #user.save
session[:user_id] = #user.id
current_user = #user.id
redirect_to '/status'
else
redirect_to '/signup'
end
end
private
def user_params
params.require(:user).permit(:first_name, :last_name, :email, :PESEL, :phone, :password,:cv)
end
end
View for new user with attachement:
<div class="login">
<div class="container">
<div class="form">
<h1>SIGN UP</h1>
<%= form_for #users,:html=> {:multipart=>true} do |f| %>
<%= f.text_field :first_name, :placeholder => "First name" %>
<%= f.text_field :last_name, :placeholder => "Last name" %>
<%= f.email_field :email, :placeholder => "Email" %>
<%= f.text_field :PESEL, :placeholder => "PESEL number" %>
<%= f.phone_field :phone, :placeholder => "Phone Number" %>
<%= f.password_field :password, :placeholder => "Password" %>
<p>CV</p>
<%= f.file_field :cv, name: "CV", class: 'form-control' %>
<%= f.submit "Sign up", class: "btn-submit" %>
<% end %>
</div>
</div>
</div>
Some logs from console:
Started POST "/users" for 127.0.0.1 at 2016-05-18 03:55:17 +0200
Processing by UsersController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Fw6easThY51CDppDDVfqO0ProQITaltqP3DaIL3An67ey4vGXh2yEerhhhxoo3bTp/mKbkIaAmktzBviBIjg8g==", "user"=>{"first_name"=>"Test", "last_name"=>"Test", "email"=>"test#t.pl", "PESEL"=>"91020300441", "phone"=>"609123123", "password"=>"[FILTERED]"}, "CV"=>#<ActionDispatch::Http::UploadedFile:0x007f25790c1b60 #tempfile=#<Tempfile:/tmp/RackMultipart20160518-26849-rqaabr.pdf>, #original_filename="pdf-test.pdf", #content_type="application/pdf", #headers="Content-Disposition: form-data; name=\"CV\"; filename=\"pdf-test.pdf\"\r\nContent-Type: application/pdf\r\n">, "commit"=>"Sign up"}
(0.1ms) BEGIN
User Exists (1.4ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = BINARY 'test#t.pl' LIMIT 1
User Exists (0.1ms) SELECT 1 AS one FROM `users` WHERE `users`.`PESEL` = BINARY '91020300441' LIMIT 1
SQL (0.1ms) INSERT INTO `users` (`first_name`, `last_name`, `email`, `PESEL`, `phone`, `password_digest`, `created_at`, `updated_at`) VALUES ('Test', 'Test', 'test#t.pl', '91020300441', '609123123', '$2a$10$HmHAiJkHv1Tada/OpzKXKOISiwumoFKTy48tFpNBYuATq/A5GaC9G', '2016-05-18 01:55:17', '2016-05-18 01:55:17')
SQL (1.0ms) INSERT INTO `job_apps` (`user_id`, `created_at`, `updated_at`) VALUES (35, '2016-05-18 01:55:17', '2016-05-18 01:55:17')
(3.0ms) COMMIT
Redirected to http://localhost:3000/status
Completed 302 Found in 135ms (ActiveRecord: 8.2ms)
Started GET "/status" for 127.0.0.1 at 2016-05-18 03:55:17 +0200
Processing by JobAppsController#index as HTML
You have overridden the name attribute of the file_field, which has broken Rails naming conventions. If you remove the name attribute, Rails will be able to pass the file details uploaded in the :cv field to the database.
Change the file_field to this:
<%= f.file_field :cv, class: 'form-control' %>
If you have Javascript attached to the form, and need to refer to the file_field element, you can use this, instead:
<%= f.file_field :cv, id: "cv", class: "form-control" %>
when I attempt to run my code, I got the error above.
I try to add specific attributes to my products, but every time I try to add them to my product, a new one is created instead of just edit the old.
Here is the result :
Started POST "/my_products" for 127.0.0.1 at 2016-01-03 16:33:46 +0100
[localhost] [127.0.0.1] [a6533ae8-475f-4e] Processing by MyProductsController#create as JS
[localhost] [127.0.0.1] [a6533ae8-475f-4e] Parameters: {"utf8"=>"✓", "my_product"=>{"size_name"=>"Gros oeuf", "size_img"=>"big-egg.png", "size_price"=>"40"}, "commit"=>"Choisir"}
[localhost] [127.0.0.1] [a6533ae8-475f-4e] (0.2ms) BEGIN
[localhost] [127.0.0.1] [a6533ae8-475f-4e] SQL (0.3ms) INSERT INTO `my_products` (`size_name`, `size_price`, `size_img`, `created_at`, `updated_at`) VALUES ('Gros oeuf', '40', 'big-egg.png', '2016-01-03 15:33:46', '2016-01-03 15:33:46')
[localhost] [127.0.0.1] [a6533ae8-475f-4e] (2.0ms) COMMIT
My application_controller.rb :
def current_product
if !session[:my_product_id].nil?
MyProduct.find(session[:my_product_id])
else
MyProduct.new
end
end
My Products_controller :
def base
#myproduct = current_product
#size = Size.all
#chocolate = MyProductItem.where(item_category_id: 1)
end
def create
#myproduct = current_product
if #myproduct.update(my_product_params)
redirect_to(:back)
else
render 'new'
end
end
My base.html.erb :
<% #size.each do |size| %>
<div class="Box" >
<p><%= size.name %></p>
<p><%= image_tag size.image, style: 'width:7em;height:auto;' %></p>
<p><%= number_to_currency size.price %></p>
<p><%= size.description.try(:html_safe) %></p>
<%= form_for #myproduct, remote: true do |f| %>
<%= f.hidden_field :size_name, value: size.name %>
<%= f.hidden_field :size_img, value: size.image %>
<%= f.hidden_field :size_price, value: size.price %>
<%= f.submit "Choisir", class: "addtocart", :id => "#orders" %>
<% end %>
</div>
<% end %>
My models :
class MyProduct < ActiveRecord::Base
attr_accessible :name, :slug, :price, :image, :my_product_item_id, :user_id, :size_name, :size_img, :size_price
has_many :elements, dependent: :destroy
has_one :size, dependent: :destroy
belongs_to :user
belongs_to :order
class Size < ActiveRecord::Base
attr_accessible :name, :price, :weight, :image, :description, :object_size
belongs_to :my_product
end
Any idea ?
Add field with proper :my_product_id value into the form:
<%= hidden_field_tag(:my_product_id, #my_product.id) if #my_product %>
If you invoke base action with GET request without parameters new object will be created, for update you must pass to this action parameter my_product_id=value (value is an id of updated product).
My form is updating the tester record (which is an end user). I am also trying to update many applied_program records which belong to the tester.
I am sending the parameters to the controller but cannot get it to update the the applied_program records. It is trying to use all the parameters instead of just the applied program params to update it.
Form:
<%= form_for #tester, url: { controller: :admins, action: :update_tester } do |f| %>
<%= render 'shared/error_messages' %>
<%= f.label :name %>
<%= f.text_field :name, class: "input-lg" %>
...
<%= f.fields_for :applied_programs do |fml| %>
<%= fml.label :approved, "Approved: " %><%= fml.check_box :approved %>
<%= fml.hidden_field :id %>
<% end %>
<%= f.submit "Save Changes", class: "btn btn-lg btn-primary" %>
<% end %>
Tester Model:
has_many :applied_programs, :dependent => :destroy
accepts_nested_attributes_for :applied_programs
AppliedProgram Model:
belongs_to :tester
Controller:
def update_tester
#applied_programs = AppliedProgram.where(tester_id: #tester.id)
#tester.update_attributes(tester_params)
#applied_programs.each do |p|
p.update_attributes(tester_params)
end
end
def tester_params
params.require(:tester).permit(:name, :email, :phone_number, :address1,
:city, :zip_code, :country, :password, :password_confirmation,
:active, :approved, applied_programs_attributes: [ :approved, :id ])
end
The log:
Processing by AdminsController#update_tester as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"x", "tester"=>{"name"=>"Dave", "email"=>"nope#gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "applied_programs_attributes"=>{"0"=>{"approved"=>"0", "id"=>"9"}, "1"=>{"approved"=>"1", "id"=>"745"}}}, "commit"=>"Save Changes", "id"=>"16"}
Tester Load (0.1ms) SELECT `testers`.* FROM `testers` WHERE `testers`.`id` = 16 LIMIT 1
Tester Load (1.1ms) SELECT `testers`.* FROM `testers` WHERE `testers`.`remember_token` = 'x' LIMIT 1
(6.8ms) BEGIN
AppliedProgram Load (2.6ms) SELECT `applied_programs`.* FROM `applied_programs` WHERE `applied_programs`.`tester_id` = 16 AND `applied_programs`.`id` IN (9, 745)
Tester Exists (0.8ms) SELECT 1 AS one FROM `testers` WHERE (`testers`.`email` = 'nope#gmail.com' AND `testers`.`id` != 16) LIMIT 1
(0.1ms) COMMIT
AppliedProgram Load (0.1ms) SELECT `applied_programs`.* FROM `applied_programs` WHERE `applied_programs`.`tester_id` = 16
(0.1ms) BEGIN
(12.4ms) ROLLBACK
Completed 500 Internal Server Error in 95ms
ActiveRecord::UnknownAttributeError (unknown attribute: name)
You problem is the loop over the applied_programs you need to do something like:
def update_tester
#applied_programs = AppliedProgram.where(tester_id: #tester.id)
#tester.update_attributes(tester_params)
end
def tester_params
params.require(:tester).permit(:name, :email, :phone_number, :address1,
:city, :zip_code, :country, :password, :password_confirmation,
:active, :approved, applied_programs_attributes: [ :approved, :id ])
end
I have a system setup where users can post microposts (basically status updates) and upload a photo to go with the micropost.
I have:
Micropost model (has_one photo)
Photo_album model (has_many photos)
Photo model (belongs_to micropost, belongs_to photo_album)
User fills in text in text area and selects a photo. Upon submission the microposts table is updated with micropost related data such as content, created_at etc.
At the same time I want my photos table (Photo model) updated with the photo selection the user made but the correct photo album. If you look below you can see in my users_controller the instance variable #photo's value. This insures that the photo uploaded is linked to the correct photo album which is named "microposts album". It's purpose is to link up to all micropost related photos.
I have a Users_controller:
def new
#user = User.new
#micropost = Micropost.new(:user_id => users_id)
#photo = Photo.new(:photo_album_id => PhotoAlbum.where(:user_id => current_user.id, :album_title => "microposts album").first.id)
end
From a previous question I asked it was established I needed to use accepts_nested_attributes_for, fields_for in order to be able to update more than one model with one form. This is how I've set things up.
Micropost model:
class Micropost < ActiveRecord::Base
belongs_to :user
has_one :photo
accepts_nested_attributes_for :photo
attr_accessible :content, :user_id, :poster_id, :username, :image, :remote_image_url
end
Photo model:
class Photo < ActiveRecord::Base
belongs_to :photo_album
attr_accessible :photo_album_id, :photo_title, :image, :remote_image_url
mount_uploader :image, ImageUploader
end
Finally here is the micropost form:
= form_for #micropost, :remote => true do |f|
= f.fields_for #photo do |p|
= p.file_field :image
= f.hidden_field :user_id
= f.text_area :content
= f.submit "Post"
At first I got the error:
ActiveModel::MassAssignmentSecurity::Error (Can't mass-assign protected attributes: photo):
I was slightly confused because I thought the attributes were assigned automatically. At lesast thats what I read in the docs anyway. Anyway I went ahead and added :photo to the micropost model attr_accessible white list.
That first error went then I got this one:
ActiveRecord::AssociationTypeMismatch (Photo(#2169424320) expected, got ActiveSupport::HashWithIndifferentAccess(#2157396720)):
Maybe I've misunderstood how this feature works but I've read through this and also looked at the 3.2.3 api doc but not where I'm going wrong.
I would really appreciate some help with getting this to work.
Thanks in advance and I hope the long post was off putting. Just thought providing all this info would make people understand what I'm trying to do better.
Kind regards
Update:
Using :photo_attributes instead of photos gives me the following error:
Started POST "/microposts" for 127.0.0.1 at 2012-05-10 21:01:11 +0100
[02b23327ad83000f75c418d8739e7f49] [127.0.0.1] Processing by MicropostsController#create as JS
[02b23327ad83000f75c418d8739e7f49] [127.0.0.1] Parameters: {"micropost"=>{"photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x00000102c293d8 #original_filename="7seriesbmw.jpeg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"micropost[photo][image]\"; filename=\"7seriesbmw.jpeg\"\r\nContent-Type: image/jpeg\r\n", #tempfile=#<File:/var/folders/fh/fhADKPjGG8qSuCeoHCTNYE+++TI/-Tmp-/RackMultipart20120510-14787-1e1mrhh>>}, "user_id"=>"2", "content"=>"ioo"}, "commit"=>"Post", "utf8"=>"✓", "authenticity_token"=>"/y8Lr+e7xgabt60GWxnMGvCtIi7IjqrYDoA84vAqYcE=", "remotipart_submitted"=>"true", "X-Requested-With"=>"IFrame", "X-Http-Accept"=>"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01"}
[02b23327ad83000f75c418d8739e7f49] [127.0.0.1] User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1
[02b23327ad83000f75c418d8739e7f49] [127.0.0.1] Completed 500 Internal Server Error in 649ms
[02b23327ad83000f75c418d8739e7f49] [127.0.0.1]
ActiveModel::MassAssignmentSecurity::Error (Can't mass-assign protected attributes: photo):
app/controllers/microposts_controller.rb:9:in `create'
After changing the attr_accessor back to :photo instead of :photo_attributes:
Started POST "/microposts" for 127.0.0.1 at 2012-05-10 21:20:07 +0100
[985e0f204bf7ffac1f7c02fbec35ad9b] [127.0.0.1] Processing by MicropostsController#create as JS
[985e0f204bf7ffac1f7c02fbec35ad9b] [127.0.0.1] Parameters: {"micropost"=>{"photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x00000102f8a3b0 #original_filename="7seriesbmw.png", #content_type="image/png", #headers="Content-Disposition: form-data; name=\"micropost[photo][image]\"; filename=\"7seriesbmw.png\"\r\nContent-Type: image/png\r\n", #tempfile=#<File:/var/folders/fh/fhADKPjGG8qSuCeoHCTNYE+++TI/-Tmp-/RackMultipart20120510-15197-9rt2xn>>}, "user_id"=>"2", "content"=>"pp"}, "commit"=>"Post", "utf8"=>"✓", "authenticity_token"=>"/y8Lr+e7xgabt60GWxnMGvCtIi7IjqrYDoA84vAqYcE=", "remotipart_submitted"=>"true", "X-Requested-With"=>"IFrame", "X-Http-Accept"=>"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01"}
[985e0f204bf7ffac1f7c02fbec35ad9b] [127.0.0.1] User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1
[985e0f204bf7ffac1f7c02fbec35ad9b] [127.0.0.1] Completed 500 Internal Server Error in 452ms
[985e0f204bf7ffac1f7c02fbec35ad9b] [127.0.0.1]
ActiveRecord::AssociationTypeMismatch (Photo(#2180069640) expected, got ActiveSupport::HashWithIndifferentAccess(#2153916820)):
app/controllers/microposts_controller.rb:9:in `create'
Microposts controller create action:
def create
if params[:micropost][:user_id].to_i == current_user.id
#micropost = current_user.microposts.build(params[:micropost])
#comment = Comment.new(:user_id => current_user.id)
respond_to do |format|
if #micropost.save
format.js { render :post_on_springboard }
end
end
else
user = User.find_by_username(params[:micropost][:username])
#micropost = user.microposts.build(params[:micropost])
if #micropost.save
UserMailer.new_wall_post_notification(user, current_user).deliver if user.email_notification == 1
flash[:success] = "Micropost posted"
redirect_to root_path+user.username
else
flash[:error] = "#{#micropost.errors.full_messages.first}"
redirect_to root_path+user.username
end
end
end
A lot of what you are trying to do concerns relationships and you shuld be able to get rails conventions working for you. If you start writing a bunch of code for somehting fairly simple with rails that's usually a bad sign.
I would focus first on your routes actually.
If you nest photo inside albums for instance, e.g.
resources :albums do
resources :photos
end
Then you will get a lot of the paths and functionality that you want.
Make sure your forms use things like form_for [#album, #post] which will go along with your accepts_nested_attributes_for
try adding :photo_attributes to your attar_accessible list in your micropost model
That should resolve the first error, I think.
Still looking into the second.
Can you post the complete stack trace from the form, it might be an issue with your controller mothods.
changing
f.fields_for #photo
to
f.fields_for :photo
and adding
#micropost.build_photo(:photo_album_id => :photo_album_id => current_user.photo_albums.find_by_album_title("microposts album").id)
to my microposts_controller fixed my issue
class Organization < ActiveRecord::Base
has_one :picture, :dependent => :destroy
accepts_nested_attributes_for :picture
attr_accessible :address, :contect_number, :email, :name, :type_of_organization, :picture_attributes
end
class Picture < ActiveRecord::Base
belongs_to :organization
mount_uploader :avatar, AvatarUploader
attr_accessible :avatar, :organization_id
end
class OrganizationsController < ApplicationController
load_and_authorize_resource
def new
#organization = Organization.new
# #organization.attributes = Picture.new
# #picture = Picture.new
end
def create
logger.info "++++++++inside the organisation controller++++++++++"
logger.info params[:organization].inspect
#org = Organization.new(params[:organization])
if #org.save
#picture = Picture.new(:avatar => params[:organization][:picture_attributes][:avatar])
#picture.organization_id = #org.id
#picture.save
logger.info "---------- inside Avtar controller ---------------"
logger.info #picture.inspect
session[:org_id] = #org.id
redirect_to new_admin_user_path :notice => 'Organization created successfully.'
else
render 'new'
end
end
end
<div>
<h4>FillUp organization details.</h4>
<%= form_for #organization, :url => organizations_path do |f| %>
<%= f.label :name, "Name" %>
<%= f.text_field :name %>
<%= f.label :contect_number, "Contact Number" %>
<%= f.text_field :contect_number %>
<%= f.label :address, "Address" %>
<%= f.text_field :address %>
<%= f.label :website, "Website" %>
<%= f.text_field :email %>
<%= f.label :company_type, "Type" %>
<%= f.text_field :type_of_organization %>
<%= f.fields_for :picture_attributes, :html => { :multipart => true } do |p| %>
<%= p.label :avatar, "My Avatar" %>
<%= p.file_field :avatar %><br/>
<%end%>
<%= f.submit :Create, :class => 'btn btn-primary' %>
<%end%>
</div>