铁杆新手。我遇到了可怕的“语法错误,意外的$ end,期待关键字_end”
但是当我通过
运行时ruby -wc sessionscontroller.rb
它说“语法正常”。我错过了什么?
以下是代码:
class SessionsController < ApplicationController
def create
auth = request.env["omniauth.auth"]
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) ||
User.create_with_omniauth(auth)
session[:user_id] = user.id
redirect_to root_url, :notice => "Signed in!"
end
end
这是直接来自railscast的copypasta,我很困惑为什么它不起作用。谢谢!
编辑2:确切的消息:
SessionsController中的SyntaxError #create
C:/Users/xxx/Sites/test.yyyy/app/models/user.rb:8: syntax error, unexpected $end, expecting keyword_end
Rails.root: C:/Users/xxx/Sites/test.yyyy
Application Trace | Framework Trace | Full Trace
app/controllers/sessions_controller.rb:4:in `create'
编辑:堆栈跟踪:
activesupport (3.1.1) lib/active_support/dependencies.rb:456:in `load'
activesupport (3.1.1) lib/active_support/dependencies.rb:456:in `block in load_file'
activesupport (3.1.1) lib/active_support/dependencies.rb:640:in `new_constants_in'
activesupport (3.1.1) lib/active_support/dependencies.rb:455:in `load_file'
activesupport (3.1.1) lib/active_support/dependencies.rb:342:in `require_or_load'
activesupport (3.1.1) lib/active_support/dependencies.rb:489:in `load_missing_constant'
activesupport (3.1.1) lib/active_support/dependencies.rb:181:in `block in const_missing'
activesupport (3.1.1) lib/active_support/dependencies.rb:179:in `each'
activesupport (3.1.1) lib/active_support/dependencies.rb:179:in `const_missing'
activesupport (3.1.1) lib/active_support/inflector/methods.rb:124:in `block in constantize'
activesupport (3.1.1) lib/active_support/inflector/methods.rb:123:in `each'
activesupport (3.1.1) lib/active_support/inflector/methods.rb:123:in `constantize'
activesupport (3.1.1) lib/active_support/dependencies.rb:528:in `block in initialize'
activesupport (3.1.1) lib/active_support/dependencies.rb:550:in `yield'
activesupport (3.1.1) lib/active_support/dependencies.rb:550:in `default'
activesupport (3.1.1) lib/active_support/dependencies.rb:550:in `[]'
actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:61:in `controller_reference'
actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:46:in `controller'
actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:25:in `call'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:in `block in call'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in `block in recognize'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:75:in `optimized_each'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call'
actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:532:in `call'
omniauth (1.0.1) lib/omniauth/strategy.rb:366:in `call_app!'
omniauth (1.0.1) lib/omniauth/strategy.rb:330:in `callback_phase'
omniauth-oauth (1.0.0) lib/omniauth/strategies/oauth.rb:57:in `callback_phase'
omniauth (1.0.1) lib/omniauth/strategy.rb:204:in `callback_call'
omniauth (1.0.1) lib/omniauth/strategy.rb:166:in `call!'
omniauth (1.0.1) lib/omniauth/strategy.rb:148:in `call'
omniauth (1.0.1) lib/omniauth/builder.rb:34:in `call'
sass (3.1.10) lib/sass/plugin/rack.rb:54:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.3.5) lib/rack/etag.rb:23:in `call'
rack (1.3.5) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/flash.rb:243:in `call'
rack (1.3.5) lib/rack/session/abstract/id.rb:195:in `context'
rack (1.3.5) lib/rack/session/abstract/id.rb:190:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/cookies.rb:331:in `call'
activerecord (3.1.1) lib/active_record/query_cache.rb:62:in `call'
activerecord (3.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (3.1.1) lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
activesupport (3.1.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.1) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/reloader.rb:68:in `call'
rack (1.3.5) lib/rack/sendfile.rb:101:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.1.1) lib/rails/rack/logger.rb:13:in `call'
rack (1.3.5) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.1.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.5) lib/rack/lock.rb:15:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.1.1) lib/rails/engine.rb:456:in `call'
railties (3.1.1) lib/rails/rack/content_length.rb:16:in `call'
railties (3.1.1) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.3.5) lib/rack/handler/webrick.rb:59:in `service'
C:/Users/dps42/RailsInstaller/Ruby1.9.2/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
C:/Users/dps42/RailsInstaller/Ruby1.9.2/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
C:/Users/dps42/RailsInstaller/Ruby1.9.2/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'