Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##users_controller.rb
- def new
- @new_users = []
- params[:id].to_i.times do
- @new_users << User.new
- end
- end
- ##new.rhtml
- 1 <div id="usersForm">
- 2
- 3 <%= error_messages_for :user %>
- 4
- 5 <%= start_form_tag :action => 'new' %>
- 6 <table>
- 7 <thead>
- 8 <tr>
- 9 <th>Nimi</th>
- 10 <th>Salasõna</th>
- 11 <th>Salasõna uuesti</th>
- 12 <th>Amet</th>
- 13 </tr>
- 14 </thead>
- 15 <tbody>
- 16 <% @new_users.each_with_index do |user, index| %>
- 17 <%= render :partial => 'fields', :locals => { :user => user, :index => index } %>
- 18 <% end %>
- 19 </tbody>
- 20 <tfoot>
- 21 <tr>
- 22 <td colspan="4">
- 23 <%= submit_tag "Lisa kasutaja(d)" %>
- 24 </td>
- 25 </tr>
- 26 </tfoot>
- 27 </table>
- 28 <%= end_form_tag %>
- 29
- 30 </div>
- ##_fields.rhtml
- 1 <% fields_for "user[#{index}]", user do |f| %>
- 2 <tr>
- 3 <td><%= f.text_field :login, :size => 14 %></td>
- 4 <td><%= f.password_field :password, :size => 14 %></td>
- 5 <td><%= f.password_field :password_confirmation, :size => 14 %></td>
- 6 <td><%= form_permissions_select(f) %></td>
- 7 </tr>
- 8 <% end %>
- ## Error:
- stack level too deep
- Extracted source (around line #0):
- 1: <% fields_for "user[#{index}]", user do |f| %>
- 2: <tr>
- 3: <td><%= f.text_field :login, :size => 14 %></td>
- Trace:
- /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1777:in `method_missing'
- /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1778:in `method_missing'
- /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1581:in `hash'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:455:in `create_template_source'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:503:in `compile_template'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:307:in `compile_and_render_template'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:292:in `render_template'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:251:in `render_file'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:266:in `render'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/partials.rb:59:in `render_partial'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:29:in `benchmark'
- /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
- /usr/lib/ruby/1.8/benchmark.rb:307:in `realtime'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:29:in `benchmark'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/partials.rb:58:in `render_partial'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:278:in `render'
- #{RAILS_ROOT}/app/views/users/new.rhtml:17:in `_run_rhtml_users_new'
- #{RAILS_ROOT}/app/views/users/new.rhtml:16:in `_run_rhtml_users_new'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:316:in `compile_and_render_template'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:292:in `render_template'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:251:in `render_file'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:726:in `render_file'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:648:in `render_with_no_layout'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/layout.rb:245:in `render_without_benchmark'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in `render'
- /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in `render'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:942:in `perform_action_without_filters'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in `perform_action_without_benchmark'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'
- /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in `perform_action'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in `process_without_filters'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in `process_without_session_management_support'
- /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in `process'
- /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in `dispatch'
- /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:115:in `handle_dispatch'
- /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:81:in `service'
- /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
- /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
- /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
- /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
- /usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
- /usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
- /usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
- /usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
- /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:67:in `dispatch'
- /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/servers/webrick.rb:59
- /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
- /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'
- /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/server.rb:30
- /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
- /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'
- script/server:3
- ##user.rb
- require 'digest/sha1'
- class User < ActiveRecord::Base
- has_many :messages
- belongs_to :permission
- # Virtual attribute for the unencrypted password
- attr_accessor :password
- validates_presence_of :login
- validates_presence_of :password, :if => :password_required?
- validates_presence_of :password_confirmation, :if => :password_required?
- validates_length_of :password, :within => 4..40, :if => :password_required?
- validates_confirmation_of :password, :if => :password_required?
- validates_length_of :login, :within => 3..40
- validates_uniqueness_of :login, :case_sensitive => false
- before_save :encrypt_password
- # Authenticates a user by their login name and unencrypted password. Returns the user or nil.
- def self.authenticate(login, password)
- u = find_by_login(login) # need to get the salt
- u && u.authenticated?(password) ? u : nil
- end
- # Encrypts some data with the salt.
- def self.encrypt(password, salt)
- Digest::SHA1.hexdigest("--#{salt}--#{password}--")
- end
- # Encrypts the password with the user salt
- def encrypt(password)
- self.class.encrypt(password, salt)
- end
- def authenticated?(password)
- crypted_password == encrypt(password)
- end
- def remember_token?
- remember_token_expires_at && Time.now.utc < remember_token_expires_at
- end
- # These create and unset the fields required for remembering users between browser closes
- def remember_me
- self.remember_token_expires_at = 2.weeks.from_now.utc
- self.remember_token = encrypt("#{email}--#{remember_token_expires_at}")
- save(false)
- end
- def forget_me
- self.remember_token_expires_at = nil
- self.remember_token = nil
- save(false)
- end
- def is_admin?; false; end;
- def is_teacher?; false; end;
- def is_student?; false; end;
- def is_parent?; false; end;
- def schoolclass; 0; end;
- protected
- # before filter
- def encrypt_password
- return if password.blank?
- self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--") if new_record?
- self.crypted_password = encrypt(password)
- end
- def password_required?
- crypted_password.blank? || !password.blank?
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement