Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Request
- Parameters:
- {"utf8"=>"✓",
- "_method"=>"put",
- "authenticity_token"=>"auxoUaTmvkvRvLUUh3kUP0lzYo9aTotajjYVfy01OE0=",
- "user"=>{"first_name"=>"Fabian",
- "last_name"=>"Jara",
- "email"=>"admin@example.com",
- "age"=>"35",
- "position_primary"=>"54ed0c136c6f6337ff0a0000",
- "position_secundary"=>"54ed0c136c6f6337ff0a0011"},
- "commit"=>"Update"}
- class User
- include Mongoid::Document
- include Mongoid::Timestamps
- include User::AuthDefinitions
- include User::Roles
- include Mongoid::Paperclip
- has_many :identities
- embeds_one :position_primary, class_name: "Position"
- embeds_one :position_secundary, class_name: "Position"
- accepts_nested_attributes_for :position_primary, :position_secundary
- has_mongoid_attached_file :image
- validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
- field :first_name, type: String
- field :last_name, type: String
- field :roles_mask, type: Integer
- field :age, type: Integer
- end
- class Position
- include Mongoid::Document
- field :name, type: String
- field :status, type: Boolean
- embedded_in :users
- end
- <h2>Edit <%= resource_name.to_s.humanize %></h2>
- <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :class => 'form-vertical' }) do |f| %>
- <%= f.input :first_name, :autofocus => true %>
- <%= f.input :last_name %>
- <%= f.input :email, :required => true %>
- <%= f.input :age %>
- <%= f.file_field :image %> <br>
- <%= f.select :position_primary, Position.all.collect {|p| [ p.name, p.id ] }, :prompt => "Select a position" %>
- <br>
- <%= f.select :position_secundary, Position.all.collect {|p| [ p.name, p.id ] }, :prompt => "Select a position" %>
- <br>
- <% if current_user.password_required? %>
- <%= f.input :password, :autocomplete => "off", :hint => "leave it blank if you don't want to change it", :required => false %>
- <%= f.input :password_confirmation, :required => false %>
- <%= f.input :current_password, :hint => "we need your current password to confirm your changes", :required => true %>
- <% end %>
- <%= f.button :submit, 'Update', :class => 'btn-primary' %>
- <% end %>
- <h3>Cancel my account</h3>
- <p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %>.</p>
- class Users::RegistrationsController < Devise::RegistrationsController
- before_filter :resource_params, if: :devise_controller?
- def resource_params
- devise_parameter_sanitizer.for(:sign_up) {|user| user.permit(:first_name, :last_name, :email, :password, :password_confirmation)}
- devise_parameter_sanitizer.for(:account_update) {|user| user.permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password)}
- end
- def update
- authorize! :update, @user, :message => 'Not authorized as an administrator.'
- respond_to do |format|
- if @user.update_attributes(user_params)
- format.html { redirect_to @user, notice: 'User was successfully updated.' }
- else
- format.html { render action: 'edit' }
- end
- end
- end
- # Never trust parameters from the scary internet, only allow the white list through.
- def user_params
- params.require(:user).permit(:email, :first_name, :last_name, :image, :age, :position_primary, :position_secundary, :roles => [])
- end
- private :resource_params
- end
- u2 = User.new(name: 'my_name', email: 'my_email@domain.com', password: 'pass', password_confirmation: 'pass', rol: [Rol.new(nombre: 'admin', description: '...')])
- u2.save!
- u2 = User.new(name: 'my_name', email: 'my_email@domain.com', password: 'pass', password_confirmation: 'pass', rol: Rol.new(nombre: 'admin', description: '...'))
- u2.save!
- class MyModel
- include Mongoid::Document
- field :my_field, type: String
- end
- class MyModel
- include Mongoid::Document
- embeds_one :my_field, class_name: 'MyNestedModel'
- end
Add Comment
Please, Sign In to add comment