2011-08-08 6 views
11

मुझे अपने ब्रांड के नए रेल 3.1 आरसी 5 एप्लिकेशन के उत्पादन मोड में चल रहे कुछ अजीब यादृच्छिक दुर्घटनाएं दिखाई देती हैं। बैकएंड 3 पतली घटनाओं के साथ nginx है।उत्पादन में रेल 3.1 के साथ यादृच्छिक दुर्घटनाएं

[Exception] users#show (NoMethodError) "undefined method `text?' for nil:NilClass" 

undefined method `text?' for nil:NilClass 
 activerecord (3.1.0.rc5) lib/active_record/validations/uniqueness.rb:57:in `build_relation' 

मैंने लॉग ऑन किया: डीबग। हालांकि एकमात्र जानकारी "आंतरिक सर्वर त्रुटि" है जिसे किसी ने पहले देखा था? पहचान मानचित्र ओम हो गया है ...

यदि मैं पतली को पुनरारंभ करता हूं, तो रेल कुछ घंटों तक बिना किसी समस्या के दौड़ेंगे।

अद्यतन 1: ऐसा लगता है कि यह मेरे सभी नियंत्रक क्रियाएं हैं जो इस त्रुटि को यादृच्छिक रूप से उत्पन्न करते हैं। आज सुबह मुझे उपरोक्त त्रुटि के साथ एक ईमेल मिला। अगर मैं लिंक का पालन करता हूं, तो पेज किसी समस्या के साथ उत्पन्न नहीं होता है।

मैं सोच रहा था कि क्या यह समस्या किसी कुकी से उपयोगकर्ता को लोड करने में समस्या से संबंधित हो सकती है?

class ApplicationController < ActionController::Base 
    protect_from_forgery 
    layout "content_with_sidebar" 
    before_filter :system 

    rescue_from CanCan::AccessDenied do |exception| 
    flash[:warning] = "Ingen adgang!" 
    redirect_to root_url 
    end 

    def system 
    if current_user 
     unless current_user.email_verified == "t" 
     flash[:warning] = 'Please activate your account.' 
     end 
     current_user.last_seen = Time.now 
     current_user.save # <--- line 18 
     @new_messages = Message.new_messages(current_user).count 
    end 
    end 

    helper_method :current_user 

    private 

    def current_user 
    if cookies[:auth_token] 
     @current_user ||= User.find_by_auth_token!(cookies[:auth_token]) 
    end 
    end 
end 

कोड उदाहरण उपयोगकर्ता # से दिखाएँ

class UsersController < ApplicationController 
    before_filter :ensure_current_user_url, :only => :show 
    load_and_authorize_resource 

    def ensure_current_user_url 
    @user = User.find(params[:id].downcase) 
    redirect_to @user, :status => :moved_permanently unless @user.friendly_id_status.best? 
    end 

    def show 
    if params[:do] == "guestbook" 
     @comment = @user.comments.new 
     @comments = @user.comments.includes(:author).order("created_at DESC").all(:limit => 5) 
    else 
     @recent_comments = @user.comments(:order => "created_at DESC") 
    end 
    @arts = @user.arts.order("created_at desc").includes([:author, :category]).page(params[:page]).per(24) 
    render :layout => "content_with_sidebar_whitebox" 
    end 

Update2 यह जानकारी मुझे मिल गया डिबग के साथ जोड़ा है।

************** username 
************** ["id", "username", "email", "email_verified", "birthday", "firstname", "lastname", "phone", "website", "profile", "last_seen", "administrator", "cached_slug", "password_salt", "crypted_password", "avatar", "avatar_cache", "comments_count", "arts_count", "auth_token", "account_activation_token", "account_activation_sent_at", "password_reset_token", "password_reset_sent_at", "created_at", "updated_at", "cheapest", "most_expensive"] 
************** email 
************** ["id", "username", "email", "email_verified", "birthday", "firstname", "lastname", "phone", "website", "profile", "last_seen", "administrator", "cached_slug", "password_salt", "crypted_password", "avatar", "avatar_cache", "comments_count", "arts_count", "auth_token", "account_activation_token", "account_activation_sent_at", "password_reset_token", "password_reset_sent_at", "created_at", "updated_at", "cheapest", "most_expensive"] 

यह आज सुबह एक दुर्घटना से एक पूर्ण स्टैक ट्रेस है।

Started GET "/messages" for filtered-ip at 2011-08-15 12:13:17 -0400 


Processing by MessagesController#index as HTML 
    User Load (1.5ms) SELECT "users".* FROM "users" WHERE "users"."auth_token" = '380e8b776cb8e3c5fd7d8b777b6d2073' ORDER BY last_seen desc LIMIT 1 
    (0.3ms) BEGIN 
    (0.9ms) SELECT 1 FROM "users" WHERE ("users"."username" = 'samia-dk' AND "users"."id" != 483) LIMIT 1 
    (0.9ms) SELECT 1 FROM "users" WHERE ("users"."email" = '[email protected]' AND "users"."id" != 483) LIMIT 1 
    (0.4ms) ROLLBACK 
Completed 500 Internal Server Error in 14ms 
Rendered /usr/local/rvm/gems/[email protected]/gems/exception_notification_rails3-1.2.0/lib/exception_notifier/views/exception_notifier/_request.text.erb (0.8ms) 
Rendered /usr/local/rvm/gems/[email protected]/gems/exception_notification_rails3-1.2.0/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.4ms) 
Rendered /usr/local/rvm/gems/[email protected]/gems/exception_notification_rails3-1.2.0/lib/exception_notifier/views/exception_notifier/_session.text.erb (0.9ms) 
Rendered /usr/local/rvm/gems/[email protected]/gems/exception_notification_rails3-1.2.0/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.1ms) 
Rendered /usr/local/rvm/gems/[email protected]/gems/exception_notification_rails3-1.2.0/lib/exception_notifier/views/exception_notifier/_environment.text.erb (55.3ms) 
Rendered /usr/local/rvm/gems/[email protected]/gems/exception_notification_rails3-1.2.0/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.3ms) 
Rendered /usr/local/rvm/gems/[email protected]/gems/exception_notification_rails3-1.2.0/lib/exception_notifier/views/exception_notifier/_backtrace.text.erb (1.7ms) 
Rendered /usr/local/rvm/gems/[email protected]/gems/exception_notification_rails3-1.2.0/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.2ms) 
Rendered /usr/local/rvm/gems/[email protected]/gems/exception_notification_rails3-1.2.0/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb (71.8ms) 

Sent mail to [email protected] (3072ms) 
Date: Mon, 15 Aug 2011 12:13:18 -0400 
From: Exception Notifier <[email protected]> 
To: [email protected] 
Message-ID: <[email protected]> 
Subject: [Exception] messages#index (NoMethodError) "undefined method `text?' 
for nil:NilClass" 
Mime-Version: 1.0 
Content-Type: text/plain; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 

A NoMethodError occurred in messages#index: 

    undefined method `text?' for nil:NilClass 
    config/initializers/some_debug.rb:6:in `build_relation' 

------------------------------- 
Request: 
------------------------------- 

    * URL  : http://www.myblog.dk/messages 
    * IP address: filtered 
    * Parameters: {"action"=>"index", "controller"=>"messages"} 
    * Rails root: /home/atmorell/Dropbox/myblog5 

------------------------------- 
Session: 
------------------------------- 

    * session id: nil 
    * data: {"_csrf_token"=>"filtered=", 
    "user_credentials"=>true, 
    "user_credentials_id"=>483} 

------------------------------- 
Environment: 
------------------------------- 

    * GATEWAY_INTERFACE       : CGI/1.2 
    * HTTP_ACCEPT        : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
    * HTTP_ACCEPT_CHARSET      : ISO-8859-1,utf-8;q=0.7,*;q=0.7 
    * HTTP_ACCEPT_ENCODING      : gzip, deflate 
    * HTTP_ACCEPT_LANGUAGE      : en,da;q=0.7,en-us;q=0.3 
    * HTTP_CONNECTION       : close 
    * HTTP_COOKIE        : __utma=52641074.268317442.1313423882.1313423882.1313423882.1; __utmb=52641074.53.10.1313423882; __utmc=52641074; __utmz=52641074.1313423882.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _myblog_session5=ed471364634fcd3b44c7bb0eae758b14; user_credentials=true%3A%3A483; auth_token=filtered 
    * HTTP_HOST         : www.myblog.dk 
    * HTTP_REFERER        : http://www.myblog.dk/messages/new 
    * HTTP_USER_AGENT       : Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0 
    * HTTP_VERSION        : HTTP/1.0 
    * PATH_INFO         : /messages 
    * QUERY_STRING        : 
    * REMOTE_ADDR        : filtered-ip 
    * REQUEST_METHOD       : GET 
    * REQUEST_PATH        : /messages 
    * REQUEST_URI        : /messages 
    * SCRIPT_NAME        : 
    * SERVER_NAME        : www.myblog.dk 
    * SERVER_PORT        : 80 
    * SERVER_PROTOCOL       : HTTP/1.1 
    * SERVER_SOFTWARE       : thin 1.2.11 codename Bat-Shit Crazy 
    * action_controller.instance    : messages#index 
    * action_dispatch.cookies     : #<ActionDispatch::Cookies::CookieJar:0x00000008766b98> 
    * action_dispatch.parameter_filter   : [:password, /RAW_POST_DATA/] 
    * action_dispatch.remote_ip     : filtered-ip 
    * action_dispatch.request.content_type  : 
    * action_dispatch.request.formats   : [text/html] 
    * action_dispatch.request.parameters  : {"action"=>"index", "controller"=>"messages"} 
    * action_dispatch.request.path_parameters : {:action=>"index", :controller=>"messages"} 
    * action_dispatch.request.query_parameters : {} 
    * action_dispatch.request.request_parameters: {} 
    * action_dispatch.routes     : #<ActionDispatch::Routing::RouteSet:0x00000002eaf658> 
    * action_dispatch.secret_token    : 93479c2e63bdb766a51f18397345cdc9a8b22ee009334171207f6b0bc2e71105d1f849de46e34965febc3b178cea662e89986e73d8922ec4915c44dca6ae4000 
    * action_dispatch.show_exceptions   : true 
    * async.callback       : #<Method: Thin::Connection#post_process> 
    * async.close        : #<EventMachine::DefaultDeferrable:0x000000087809a8> 
    * exception_notifier.options    : {:email_prefix=>"[Exception] ", :sender_address=>"\"Exception Notifier\" <[email protected]>", :exception_recipients=>["[email protected]"], :ignore_exceptions=>[ActiveRecord::RecordNotFound, AbstractController::ActionNotFound, ActionController::RoutingError]} 
    * rack-cache.allow_reload     : false 
    * rack-cache.allow_revalidate    : false 
    * rack-cache.cache_key      : Rack::Cache::Key 
    * rack-cache.default_ttl     : 0 
    * rack-cache.entitystore     : rails:/ 
    * rack-cache.metastore      : rails:/ 
    * rack-cache.private_headers    : ["Authorization", "Cookie"] 
    * rack-cache.storage      : #<Rack::Cache::Storage:0x000000029e9b50> 
    * rack-cache.verbose      : true 
    * rack.errors        : #<IO:0x00000000c27860> 
    * rack.input        : #<StringIO:0x00000008784c10> 
    * rack.multiprocess       : false 
    * rack.multithread       : false 
    * rack.request.cookie_hash     : {"__utma"=>"52641074.268317442.1313423882.1313423882.1313423882.1", "__utmb"=>"52641074.53.10.1313423882", "__utmc"=>"52641074", "__utmz"=>"52641074.1313423882.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)", "_myblog_session5"=>"ed471364634fcd3b44c7bb0eae758b14", "user_credentials"=>"true::483", "auth_token"=>"filtered"} 
    * rack.request.cookie_string    : __utma=52641074.268317442.1313423882.1313423882.1313423882.1; __utmb=52641074.53.10.1313423882; __utmc=52641074; __utmz=52641074.1313423882.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _myblog_session5=ed471364634fcd3b44c7bb0eae758b14; user_credentials=true%3A%3A483; auth_token=filtered 
    * rack.request.query_hash     : {} 
    * rack.request.query_string     : 
    * rack.run_once        : false 
    * rack.session        : {"_csrf_token"=>"jlK/filtered=", "user_credentials"=>true, "user_credentials_id"=>483} 
    * rack.session.options      : {:key=>"_myblog_session5", :path=>"/", :domain=>nil, :expire_after=>nil, :secure=>false, :httponly=>true, :defer=>false, :renew=>false, :id=>"ed471364634fcd3b44c7bb0eae758b14"} 
    * rack.session.record      : #<ActiveRecord::SessionStore::Session:0x000000087762f0> 
    * rack.url_scheme       : http 
    * rack.version        : [1, 0] 

    * Process: 1938 
    * Server : li267-196 

------------------------------- 
Backtrace: 
------------------------------- 

    config/initializers/some_debug.rb:6:in `build_relation' 
    activerecord (3.1.0.rc5) lib/active_record/validations/uniqueness.rb:25:in `validate_each' 
    activemodel (3.1.0.rc5) lib/active_model/validator.rb:153:in `block in validate' 
    activemodel (3.1.0.rc5) lib/active_model/validator.rb:150:in `each' 
    activemodel (3.1.0.rc5) lib/active_model/validator.rb:150:in `validate' 
    activesupport (3.1.0.rc5) lib/active_support/callbacks.rb:302:in `_callback_before_483' 
    activesupport (3.1.0.rc5) lib/active_support/callbacks.rb:622:in `_run_validate_callbacks' 
    activesupport (3.1.0.rc5) lib/active_support/callbacks.rb:81:in `run_callbacks' 
    activemodel (3.1.0.rc5) lib/active_model/validations.rb:212:in `run_validations!' 
    activemodel (3.1.0.rc5) lib/active_model/validations/callbacks.rb:53:in `block in run_validations!' 
    activesupport (3.1.0.rc5) lib/active_support/callbacks.rb:401:in `_run_validation_callbacks' 
    activesupport (3.1.0.rc5) lib/active_support/callbacks.rb:81:in `run_callbacks' 
    activemodel (3.1.0.rc5) lib/active_model/validations/callbacks.rb:53:in `run_validations!' 
    activemodel (3.1.0.rc5) lib/active_model/validations.rb:179:in `valid?' 
    activerecord (3.1.0.rc5) lib/active_record/validations.rb:69:in `valid?' 
    activerecord (3.1.0.rc5) lib/active_record/validations.rb:77:in `perform_validations' 
    activerecord (3.1.0.rc5) lib/active_record/validations.rb:50:in `save' 
    activerecord (3.1.0.rc5) lib/active_record/attribute_methods/dirty.rb:22:in `save' 
    activerecord (3.1.0.rc5) lib/active_record/transactions.rb:241:in `block (2 levels) in save' 
    activerecord (3.1.0.rc5) lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status' 
    activerecord (3.1.0.rc5) lib/active_record/connection_adapters/abstract/database_statements.rb:183:in `transaction' 
    activerecord (3.1.0.rc5) lib/active_record/transactions.rb:208:in `transaction' 
    activerecord (3.1.0.rc5) lib/active_record/transactions.rb:293:in `with_transaction_returning_status' 
    activerecord (3.1.0.rc5) lib/active_record/transactions.rb:241:in `block in save' 
    activerecord (3.1.0.rc5) lib/active_record/transactions.rb:252:in `rollback_active_record_state!' 
    activerecord (3.1.0.rc5) lib/active_record/transactions.rb:240:in `save' 
    app/controllers/application_controller.rb:18:in `system' 
    activesupport (3.1.0.rc5) lib/active_support/callbacks.rb:430:in `_run__163591495713425608__process_action__3187008165500041637__callbacks' 
    activesupport (3.1.0.rc5) lib/active_support/callbacks.rb:386:in `_run_process_action_callbacks' 
    activesupport (3.1.0.rc5) lib/active_support/callbacks.rb:81:in `run_callbacks' 
    actionpack (3.1.0.rc5) lib/abstract_controller/callbacks.rb:17:in `process_action' 
    actionpack (3.1.0.rc5) lib/action_controller/metal/rescue.rb:17:in `process_action' 
    actionpack (3.1.0.rc5) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' 
    activesupport (3.1.0.rc5) lib/active_support/notifications.rb:55:in `block in instrument' 
    activesupport (3.1.0.rc5) lib/active_support/notifications/instrumenter.rb:21:in `instrument' 
    activesupport (3.1.0.rc5) lib/active_support/notifications.rb:55:in `instrument' 
    actionpack (3.1.0.rc5) lib/action_controller/metal/instrumentation.rb:29:in `process_action' 
    actionpack (3.1.0.rc5) lib/action_controller/metal/params_wrapper.rb:202:in `process_action' 
    activerecord (3.1.0.rc5) lib/active_record/railties/controller_runtime.rb:18:in `process_action' 
    actionpack (3.1.0.rc5) lib/abstract_controller/base.rb:121:in `process' 
    actionpack (3.1.0.rc5) lib/abstract_controller/rendering.rb:45:in `process' 
    actionpack (3.1.0.rc5) lib/action_controller/metal.rb:193:in `dispatch' 
    actionpack (3.1.0.rc5) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch' 
    actionpack (3.1.0.rc5) lib/action_controller/metal.rb:236:in `block in action' 
    actionpack (3.1.0.rc5) lib/action_dispatch/routing/route_set.rb:65:in `call' 
    actionpack (3.1.0.rc5) lib/action_dispatch/routing/route_set.rb:65:in `dispatch' 
    actionpack (3.1.0.rc5) lib/action_dispatch/routing/route_set.rb:29:in `call' 
    rack-mount (0.8.2) lib/rack/mount/route_set.rb:152:in `block in call' 
    rack-mount (0.8.2) lib/rack/mount/code_generation.rb:96:in `block in recognize' 
    rack-mount (0.8.2) lib/rack/mount/code_generation.rb:68:in `optimized_each' 
    rack-mount (0.8.2) lib/rack/mount/code_generation.rb:95:in `recognize' 
    rack-mount (0.8.2) lib/rack/mount/route_set.rb:141:in `call' 
    actionpack (3.1.0.rc5) lib/action_dispatch/routing/route_set.rb:531:in `call' 
    oa-core (0.2.6) lib/omniauth/strategy.rb:44:in `call!' 
    oa-core (0.2.6) lib/omniauth/strategy.rb:30:in `call' 
    oa-core (0.2.6) lib/omniauth/strategy.rb:44:in `call!' 
    oa-core (0.2.6) lib/omniauth/strategy.rb:30:in `call' 
    oa-core (0.2.6) lib/omniauth/strategy.rb:44:in `call!' 
    oa-core (0.2.6) lib/omniauth/strategy.rb:30:in `call' 
    oa-core (0.2.6) lib/omniauth/builder.rb:30:in `call' 
    exception_notification_rails3 (1.2.0) lib/exception_notifier.rb:34:in `call' 
    actionpack (3.1.0.rc5) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' 
    rack (1.3.2) lib/rack/etag.rb:23:in `call' 
    rack (1.3.2) lib/rack/conditionalget.rb:25:in `call' 
    actionpack (3.1.0.rc5) lib/action_dispatch/middleware/head.rb:14:in `call' 
    actionpack (3.1.0.rc5) lib/action_dispatch/middleware/params_parser.rb:21:in `call' 
    actionpack (3.1.0.rc5) lib/action_dispatch/middleware/flash.rb:243:in `call' 
    rack (1.3.2) lib/rack/session/abstract/id.rb:195:in `context' 
    rack (1.3.2) lib/rack/session/abstract/id.rb:190:in `call' 
    actionpack (3.1.0.rc5) lib/action_dispatch/middleware/cookies.rb:326:in `call' 
    activerecord (3.1.0.rc5) lib/active_record/query_cache.rb:62:in `call' 
    activerecord (3.1.0.rc5) lib/active_record/connection_adapters/abstract/connection_pool.rb:466:in `call' 
    actionpack (3.1.0.rc5) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' 
    activesupport (3.1.0.rc5) lib/active_support/callbacks.rb:392:in `_run_call_callbacks' 
    activesupport (3.1.0.rc5) lib/active_support/callbacks.rb:81:in `run_callbacks' 
    actionpack (3.1.0.rc5) lib/action_dispatch/middleware/callbacks.rb:28:in `call' 
    rack (1.3.2) lib/rack/sendfile.rb:101:in `call' 
    actionpack (3.1.0.rc5) lib/action_dispatch/middleware/remote_ip.rb:48:in `call' 
    actionpack (3.1.0.rc5) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call' 
    railties (3.1.0.rc5) lib/rails/rack/logger.rb:13:in `call' 
    rack (1.3.2) lib/rack/methodoverride.rb:24:in `call' 
    rack (1.3.2) lib/rack/runtime.rb:17:in `call' 
    activesupport (3.1.0.rc5) lib/active_support/cache/strategy/local_cache.rb:72:in `call' 
    rack (1.3.2) lib/rack/lock.rb:15:in `call' 
    actionpack (3.1.0.rc5) lib/action_dispatch/middleware/static.rb:53:in `call' 
    rack-cache (1.0.2) lib/rack/cache/context.rb:132:in `forward' 
    rack-cache (1.0.2) lib/rack/cache/context.rb:243:in `fetch' 
    rack-cache (1.0.2) lib/rack/cache/context.rb:181:in `lookup' 
    rack-cache (1.0.2) lib/rack/cache/context.rb:65:in `call!' 
    rack-cache (1.0.2) lib/rack/cache/context.rb:50:in `call' 
    railties (3.1.0.rc5) lib/rails/engine.rb:455:in `call' 
    railties (3.1.0.rc5) lib/rails/railtie/configurable.rb:30:in `method_missing' 
    thin (1.2.11) lib/thin/connection.rb:84:in `block in pre_process' 
    thin (1.2.11) lib/thin/connection.rb:82:in `catch' 
    thin (1.2.11) lib/thin/connection.rb:82:in `pre_process' 
    thin (1.2.11) lib/thin/connection.rb:57:in `process' 
    thin (1.2.11) lib/thin/connection.rb:42:in `receive_data' 
    eventmachine (0.12.10) lib/eventmachine.rb:256:in `run_machine' 
    eventmachine (0.12.10) lib/eventmachine.rb:256:in `run' 
    thin (1.2.11) lib/thin/backends/base.rb:61:in `start' 
    thin (1.2.11) lib/thin/server.rb:159:in `start' 
    thin (1.2.11) lib/thin/controllers/controller.rb:86:in `start' 
    thin (1.2.11) lib/thin/runner.rb:185:in `run_command' 
    thin (1.2.11) lib/thin/runner.rb:151:in `run!' 
    thin (1.2.11) bin/thin:6:in `<top (required)>' 
    /usr/local/rvm/gems/[email protected]/bin/thin:19:in `load' 
    /usr/local/rvm/gems/[email protected]/bin/thin:19:in `<main>' 



NoMethodError (undefined method `text?' for nil:NilClass): 
    config/initializers/some_debug.rb:6:in `build_relation' 
    app/controllers/application_controller.rb:18:in `system' 

User.rb

# -*- encoding : utf-8 -*- 
class User < ActiveRecord::Base 
    attr_accessible :username, :email, :birthday, :firstname, :lastname, :phone, :website, :profile, :avatar, :password, :avatar_cache, :name, :last_seen, :arts_count, :cheapest, :most_expensive #, :email_verified, :crypted_password, :password_salt, :administrator, :id 

    # Virtual attributes 
    attr_accessor :password, :password_confirmation 

    belongs_to :cheapest, :class_name => "Art", :foreign_key => :cheapest 
    belongs_to :most_expensive, :class_name => "Art", :foreign_key => :most_expensive 

    has_many :blogs, :dependent => :destroy 
    has_many :arts, :dependent => :destroy 
    has_many :authentications, :dependent => :destroy 
    has_friendly_id :username, :use_slug => true 
    has_many :comments, :as => :commentable, :validate => :false 

    mount_uploader :avatar, AvatarUploader 
    before_save :encrypt_password 
    before_create { generate_token(:auth_token) } 
    after_create { send_account_activation } 

    validates_uniqueness_of :username, :email 
    validates_presence_of :username, :email 
    validate :password_length_without_authentications 
    validates_format_of :username, :with => /^[-a-z\d_]+$/, :message => "kun små bogstaver, tal og bindestreger. f.eks. galleri-toke" 
    validates_length_of :username, :maximum=>30, :message=>"Dit brugernavn må max være 30 karakter." 
    validates_length_of :username, :minimum=>3, :message=>"Dit brugernavn skal minimum være 3 karakter." 
    validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i 

    default_scope :order => "last_seen desc" #, :conditions => "username NOT LIKE 'robot'" 
    scope :with_arts, where("arts_count > 0") 
... 

हर बार जब उपयोगकर्ता द्वारा पृष्ठ रीफ़्रेश मैं last_seen स्तंभ को अद्यतन करने और logged_in उपयोगकर्ता को बचाने के। किसी कारण से बचत ब्रेक। मैं इसे अपने विकास सर्वर पर पुन: उत्पन्न करने में सक्षम नहीं हूं।

+1

क्या आप उपयोगकर्ता कोड से अपने कुछ कोड पोस्ट कर सकते हैं # व्यू व्यू और UserController से दिखाएं? – arnep

+0

हो गया .. मेरा अद्यतन प्रश्न देखें। – atmorell

+0

क्या आप स्टैक-ट्रेस पोस्ट कर सकते हैं? रेखा संख्या जहां त्रुटि हो रही है मदद कर सकता है। –

उत्तर

18

समाधान: अपने सत्यापन लाइन इस कहते हैं अगर ...

validates :tag, :uniqueness => {:scope => :post} 

... तो यह इस तरह के संदर्भ के लिए स्तंभ नाम संघ नाम के बजाय बदल ...

validates :tag_id, :uniqueness => {:scope => :post_id} 

मैं रेल 3.1.0.rc5 में अपनी विफलता से निर्मित है और एक ही त्रुटि संदेश का उत्पादन किया। संक्षिप्त स्पष्टीकरण यह है कि build_relation विधि में कोड एक शाब्दिक कॉलम नाम की अपेक्षा कर रहा है, न कि एक एसोसिएशन नाम।

कोड के टुकड़े सहित अधिक गहन स्पष्टीकरण के लिए http://thetenelements.blogspot.com/2011/08/undefined-method-text-for-nilnilclass.html

+0

मेरे पास बच्चों पर कोई सत्यापन नहीं है। केवल एक चीज जो मैं पा सकता था वह था: validates_uniqueness_of: body,: scope => [: commentable_id,: user_id],: message => "डुप्लिकेट रिकॉर्ड .." – atmorell

2

यदि आप अभी भी इसे हल करने में असमर्थ हैं तो build_relation विधि में कुछ डिबगिंग जोड़ें। बस यह कंसोल पर कुछ डेटा लिखने दें कि यह वास्तव में गलत कहां जाता है।

बदलें

def build_relation(klass, table, attribute, value) #:nodoc: 
    column = klass.columns_hash[attribute.to_s] 
    value = column.limit ? value.to_s.mb_chars[0, column.limit] : value.to_s if column.text? 

को
def build_relation(klass, table, attribute, value) #:nodoc: 
    puts "build_relation klass: #{klass.inspect}" 
    puts "build_relation table: #{table.inspect}" 
    puts "build_relation attribute: #{attribute.inspect}" 
    puts "build_relation value: #{value.inspect}" 
    puts "build_relation columns_hash: #{klass.columns_hash.inspect}" 
    column = klass.columns_hash[attribute.to_s] 
    value = column.limit ? value.to_s.mb_chars[0, column.limit] : value.to_s if column.text? 

तो आप कम से कम पता चल जाएगा कि क्या विशेषता यह खड़ी कर रहा है। अब आशा है कि यह एक ही हर यह गलत हो जाता है ...

+0

मैं रेल विधि को ओवरराइड कैसे करूं? क्या मुझे विधि को मेरे एप्लिकेशन नियंत्रक में रखना चाहिए? – atmorell

+0

इस डीबगिंग के लिए बस उस फ़ाइल को संपादित करें जो त्रुटि को बढ़ाता है। –

+0

मेरे पास यह वही त्रुटि है। मेरे पास रिलेशनशिप सत्यापन नहीं है, हालांकि मेरे पास एलियाड एट्रिब्यूट पर सत्यापन है। क्या यह हो सकता है कि उपनाम संबंध बनाने से इस मुद्दे का कारण बनता है? यदि ऐसा है तो आप इस मुद्दे को कैसे हल करते हैं? – Altonymous

4

ल्यूक ग्रीफिथ पर अपने ब्लॉग को देखने के आप उत्तर की सबसे दिया है। सार यह है, आपके पास कहीं विशिष्टता सत्यापन है। अपनी टिप्पणी के अनुसार केवल एक ही आप इस एक है:

validates_uniqueness_of :body, :scope => [:commentable_id, :user_id], :message => "Duplicate record.." 

अगर ऐसा है, तो हम यह दोषी है (यह पता करने के लिए कौन-सा मॉडल है कि सत्यापन किया गया था, भी करने के लिए मदद मिलेगी मदद मिलेगी की ही होगी अपने उपयोगकर्ता मॉडल कोड के प्रासंगिक भागों के साथ-साथ मॉडल के प्रासंगिक हिस्सों को देखें जहां यह सत्यापन पाया जाता है)। लेकिन इससे कोई फर्क नहीं पड़ता कि हम अभी भी अनुमान लगा सकते हैं कि आपकी समस्या क्या है।

मुद्दा आपको मिलने वाला लाइन 57. पर रेल स्रोत rails/activerecord/lib/active_record/validations/uniqueness.rb में build_relation विधि इस विधि एक विशेषता के नाम पर आधारित एक कॉलम को देखने के लिए कोशिश कर रहा है में होता है और फिर अगर यह पाठ है देखने के लिए कोशिश करता है। त्रुटियां होती हैं क्योंकि यह प्राप्त होने वाली विशेषता column के मान पर कॉलम हैश में प्रतीत नहीं होती है।

यह एक अन्य उत्तर में सुझाव दिया गया है कि आप build_relation विधि में कुछ डीबगिंग जानकारी आउटपुट करते हैं। यह एक बुरा विचार नहीं है (आपको वास्तव में यह जानने की ज़रूरत है कि कॉलम_शैश में कुंजियां क्या हैं और विधि में दी गई विशेषता का मूल्य क्या है), यहां आप यह कैसे करते हैं। config/initializers में प्रारंभकर्ता बनाएं, इसे debugging_stuff.rb पर कॉल करें। वहाँ के अंदर आप निम्नलिखित रख सकते हैं:

ActiveRecord::Validations::UniquenessValidator.class_eval do 
    def build_relation(klass, table, attribute, value) #:nodoc: 
    puts "************** #{attribute}" 
    puts "************** #{klass.columns_hash.keys.inspect}" 
    column = klass.columns_hash[attribute.to_s] 
    value = column.limit ? value.to_s.mb_chars[0, column.limit] : value.to_s if column.text? 

    if !options[:case_sensitive] && value && column.text? 
     # will use SQL LOWER function before comparison 
     relation = table[attribute].lower.eq(table.lower(value)) 
    else 
     value = klass.connection.case_sensitive_modifier(value) 
     relation = table[attribute].eq(value) 
    end 

    relation 
    end 
end 

क्या हम के लिए देख रहे पता लगाने के लिए जब columns_hash में कुंजी में से कोई भी विशेषता मान है कि पारित हो जाता है से मेल है।

यदि उपरोक्त विशिष्टता वैधता वास्तव में आपके पास है, तो यह वहां तीन गुणों में से एक होना चाहिए (:body, :commentable_id, :user_id)। मेरा पैसा :body पर है लेकिन मैं गलत हो सकता था। :body एक और मॉडल का संदर्भ लें। यदि यह संभवतः :body_id होना चाहिए क्योंकि ल्यूक ग्रिफिथ्स ने संकेत दिया था। यदि आपको अभी भी समस्या नहीं मिल रही है, तो आपको प्रासंगिक मॉडलों (उपयोगकर्ता इत्यादि) के लिए पूर्ण स्टैक ट्रेस और कोड जैसे अधिक डिबगिंग जानकारी प्रदान करने की आवश्यकता होगी - हम जहां तक ​​हमारे पास जानकारी के साथ जा सकते हैं।

संबंधित मुद्दे