我有一个模型用户:
class User < ActiveRecord::Base
before_update :randomize_file_name
attr_accessible :first_name, :last_name, :birth_date, :gender,:address,:city,:country,:landline,:mobile, :email, :password, :password_confirmation,:login,:terms_and_policy,:remember_token,:avatar, :readonly,:look
attr_accessor :terms_and_policy, :remember_me, :readonly, :password_confirmation
并且seeds.rb
:
login = Faker::Name.first_name
first_name = Faker::Name.first_name
last_name = Faker::Name.last_name
email = Faker::Internet.email
user = User.create!(login: login, first_name: first_name, last_name: last_name, email: email, address: "indore", city: "indore", country: "india", mobile:"1234567890", gender: "Male", password: "111111",password_confirmation: "111111")
puts "#{user} is created #{login}"
当我运行时rake db:create
,我收到错误:
NoMethodError Exception: undefined method `params' for main:Object
password_confirmation
我在创建时不使用user
,因为它会引发验证错误。
当我追踪它时:
rake db:seed --trace
** Invoke db:seed (first_time)
** Execute db:seed
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:abort_if_pending_migrations
rake aborted!
undefined method `params' for main:Object
authlogic
当我看到它params
被定义时,我使用了gem:
module Authlogic
module ControllerAdapters # :nodoc:
# Allows you to use Authlogic in any framework you want, not just rails. See the RailsAdapter or MerbAdapter
# for an example of how to adapt Authlogic to work with your framework.
class AbstractAdapter
attr_accessor :controller
def initialize(controller)
self.controller = controller
end
def authenticate_with_http_basic(&block)
@auth = Rack::Auth::Basic::Request.new(controller.request.env)
if @auth.provided? and @auth.basic?
block.call(*@auth.credentials)
else
false
end
end
def cookies
controller.cookies
end
def cookie_domain
raise NotImplementedError.new("The cookie_domain method has not been implemented by the controller adapter")
end
def params
controller.params
end
def request
controller.request
end
def request_content_type
request.content_type
end
def session
controller.session
end
def responds_to_single_access_allowed?
controller.respond_to?(:single_access_allowed?, true)
end
def single_access_allowed?
controller.send(:single_access_allowed?)
end
def responds_to_last_request_update_allowed?
controller.respond_to?(:last_request_update_allowed?, true)
end
def last_request_update_allowed?
controller.send(:last_request_update_allowed?)
end
private
def method_missing(id, *args, &block)
controller.send(id, *args, &block)
end
end
结尾