user.rb中意外的输入结束 - 引用另一个文件?

时间:2014-05-08 05:40:25

标签: ruby-on-rails ruby ruby-on-rails-4 devise omniauth

我试图获得omniauth-facebook并在我的用户模型中设计彼此jive。当我运行$ rails s时,我收到错误

    /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:424:in `load': /Users/maxnied/Desktop/vital_app/app/models/user.rb:38: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:424:in `block in load_file'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:616:in `new_constants_in'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:423:in `load_file'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:324:in `require_or_load'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:463:in `load_missing_constant'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:184:in `const_missing'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `const_get'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `block in constantize'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `each'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `inject'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `constantize'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:535:in `get'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:566:in `constantize'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/devise-3.2.4/lib/devise.rb:297:in `get'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/devise-3.2.4/lib/devise/mapping.rb:77:in `to'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/devise-3.2.4/lib/devise/mapping.rb:72:in `modules'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/devise-3.2.4/lib/devise/mapping.rb:89:in `routes'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/devise-3.2.4/lib/devise/mapping.rb:156:in `default_used_route'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/devise-3.2.4/lib/devise/mapping.rb:66:in `initialize'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/devise-3.2.4/lib/devise.rb:331:in `new'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/devise-3.2.4/lib/devise.rb:331:in `add_mapping'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/devise-3.2.4/lib/devise/rails/routes.rb:221:in `block in devise_for'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/devise-3.2.4/lib/devise/rails/routes.rb:220:in `each'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/devise-3.2.4/lib/devise/rails/routes.rb:220:in `devise_for'
from /Users/maxnied/Desktop/vital_app/config/routes.rb:2:in `block in <top (required)>'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:341:in `instance_exec'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:341:in `eval_block'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:319:in `draw'
from /Users/maxnied/Desktop/vital_app/config/routes.rb:1:in `<top (required)>'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `block in load'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `each'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `load_paths'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:16:in `reload!'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:26:in `block in updater'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/file_update_checker.rb:75:in `call'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/file_update_checker.rb:75:in `execute'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:27:in `updater'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `run'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/maxnied/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from /Users/maxnied/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /Users/maxnied/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from /Users/maxnied/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /Users/maxnied/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:345:in `each'
from /Users/maxnied/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:345:in `call'
from /Users/maxnied/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from /Users/maxnied/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from /Users/maxnied/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/application.rb:215:in `initialize!'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/maxnied/Desktop/vital_app/config/environment.rb:5:in `<top (required)>'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
from /Users/maxnied/Desktop/vital_app/config.ru:3:in `block in <main>'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from /Users/maxnied/Desktop/vital_app/config.ru:in `new'
from /Users/maxnied/Desktop/vital_app/config.ru:in `<main>'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/commands/server.rb:48:in `app'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/commands/server.rb:75:in `start'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/commands.rb:76:in `block in <top (required)>'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/commands.rb:71:in `tap'
from /Users/maxnied/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/commands.rb:71:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'

来自user.rb的来源:

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:facebook]
  has_one  :contact_info
  has_and_belongs_to_many :channels
  has_and_belongs_to_many :regions
  has_and_belongs_to_many :roles
  has_many :managed_campaigns, class_name: Campaign, foreign_key: :owner_id

  accepts_nested_attributes_for :contact_info

  validates_associated :contact_info, message: "is not complete"

  delegate :full_name, to: :contact_info

  def facebook
    @user = User.find_for_facebook_oauth(request.env["omniauth.auth"])

    if @user.persisted?
      sign_in_and_redirect @user, :event => :authentication 
      set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
    else
      session["devise.facebook_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end

  def self.find_for_facebook_oauth(auth)
    where(auth.slice(:provider, :uid)).first_or_create do |user|
      user.provider = auth.provider
      user.uid = auth.uid
      user.email = auth.info.email
      user.password = Devise.friendly_token[0,20]
      user.name = auth.info.name  
      user.image = auth.info.image 
    end
  end
end

我没有看到语法中缺少的结尾,虽然我完全承认我对这种语言很新,如果我这样做会感到惊讶。我系统地评论了源的每个部分,以及所有现有的结尾(并在最后添加了额外的部分)。唯一有用的是评论`def facebook&#39;到最后。一位朋友建议检查我的routes.rb文件,但我再也不熟悉语法,以辨别是否存在问题。 routes.rb如下:

VitalApp::Application.routes.draw do

devise_for:user,has_one :: contact_info#,: controllers =&gt; {:omniauth_callbacks =&gt; &#34;用户/ omniauth_callbacks&#34; }     devise_scope:用户做       得到&#34;注册&#34;,到:&#34;设计/注册#new&#34;       得到&#34;登录&#34;,到:&#34;设计/会话#new&#34;       delete&#34; logout&#34;,to:&#34; devise / sessions#destroy&#34;     结束     root&#34; home #index&#34;     资源:活动     端

非常感谢任何见解!

1 个答案:

答案 0 :(得分:2)

您缺少end方法的def facebook