【问题标题】:unexpected tIVAR while attempting to use modal for user create尝试使用模态进行用户创建时出现意外 tIVAR
【发布时间】:2016-06-28 19:34:32
【问题描述】:

我正在构建一个用于创建用户的模式(只有管理员可以创建用户。)我收到了一个意外的 tVAR 错误。我现在已经多次查看我的代码,但似乎无法找到我出错的地方。

错误是(rails 服务器输出:)

SyntaxError - syntax error, unexpected tIVAR, expecting ')'
@output_buffer.safe_append='              <...
              ^:

我创建了第二个“AdminsController” - 如下所列。 (我的目标是在成功保存时重定向到 user_show_page 或如果不成功则重定向到应用程序 root_path (仅构建了显示页面,我将在以后构建索引。(我感觉这可能是我错了。)

class AdminsController < ApplicationController
  before_action :authenticate_user!
  def new_user
    authorize! :manage, User
    @user = User.new
  end

  def create_user

    @user = User.new(permitted_params.user)
    authorize! :manage, User
    if @user.save
      format.html { redirect_to root_path, notice: 'User has been successfully created.' }
    else
      format.html { redirect_to root_path, notice: 'There was a problem creating this user, please try again.' }
    end
  end

end

自定义路径的我的 routes.rb - 下面

  as :user do
    get "admins/new_user" => "admins#new_user", as: :admins_new_user
    post "admins/create_user/:id" => "admins#create_user", as: :admins_create_user
  end

我的模态形式 - 如下:

  <!-- Start - Modles -->
    <!-- Start - New User Creation -->
    <%= form_for(@user, :url => admins_create_user_path do |f| %>
      <div class="modal fade" id="userCreate" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog modal-lg" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title" id="myModalLabel">Create New System User</h4>
            </div>
            <div class="modal-body">
              Form Fields HERE....
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              <%= f.submit "Create User", :class => 'btn btn-primary' %>
            </div>
          </div>
        </div>
      </div>
    <% end %>
    <!-- End - New User Creation -->
  <!-- End - Modles -->

模态框已放置在 application.html.erb 页面上——这也可能是问题所在?不过我不知道还能把它放在哪里..

最后,我的模态链接(在导航栏中找到):

<%= link_to "Create New User", "#userCreate", "data-toggle" => "modal" %>

任何帮助将不胜感激!如果您需要任何进一步的信息,请告诉我。

全回溯:

Started GET "/" for ::1 at 2016-06-28 13:38:54 -0600
Processing by Users::SessionsController#new as HTML
  Rendering users/sessions/new.html.erb within layouts/application
  Rendered users/shared/_links.html.erb (1.7ms)
  Rendered users/sessions/new.html.erb within layouts/application (5.4ms)
Completed 500 Internal Server Error in 16ms (ActiveRecord: 0.0ms)



SyntaxError - syntax error, unexpected tIVAR, expecting ')'
@output_buffer.safe_append='    <!-- End - New User Creation -->
              ^:
  app/views/layouts/application.html.erb:123:in `'
  actionview (5.0.0.rc1) lib/action_view/template.rb:309:in `module_eval'
  actionview (5.0.0.rc1) lib/action_view/template.rb:309:in `compile'
  actionview (5.0.0.rc1) lib/action_view/template.rb:258:in `block (2 levels) in compile!'
  activesupport (5.0.0.rc1) lib/active_support/notifications.rb:166:in `instrument'
  actionview (5.0.0.rc1) lib/action_view/template.rb:350:in `instrument'
  actionview (5.0.0.rc1) lib/action_view/template.rb:257:in `block in compile!'
  actionview (5.0.0.rc1) lib/action_view/template.rb:245:in `synchronize'
  actionview (5.0.0.rc1) lib/action_view/template.rb:245:in `compile!'
  actionview (5.0.0.rc1) lib/action_view/template.rb:157:in `block in render'
  activesupport (5.0.0.rc1) lib/active_support/notifications.rb:166:in `instrument'
  actionview (5.0.0.rc1) lib/action_view/template.rb:348:in `instrument'
  actionview (5.0.0.rc1) lib/action_view/template.rb:156:in `render'
  actionview (5.0.0.rc1) lib/action_view/renderer/template_renderer.rb:66:in `render_with_layout'
  actionview (5.0.0.rc1) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
  actionview (5.0.0.rc1) lib/action_view/renderer/template_renderer.rb:14:in `render'
  actionview (5.0.0.rc1) lib/action_view/renderer/renderer.rb:42:in `render_template'
  actionview (5.0.0.rc1) lib/action_view/renderer/renderer.rb:23:in `render'
  actionview (5.0.0.rc1) lib/action_view/rendering.rb:103:in `_render_template'
  actionpack (5.0.0.rc1) lib/action_controller/metal/streaming.rb:217:in `_render_template'
  actionview (5.0.0.rc1) lib/action_view/rendering.rb:83:in `render_to_body'
  actionpack (5.0.0.rc1) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
  actionpack (5.0.0.rc1) lib/action_controller/metal/renderers.rb:144:in `render_to_body'
  actionpack (5.0.0.rc1) lib/abstract_controller/rendering.rb:26:in `render'
  actionpack (5.0.0.rc1) lib/action_controller/metal/rendering.rb:36:in `render'
  actionpack (5.0.0.rc1) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
  activesupport (5.0.0.rc1) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
  /Users/developer/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
  activesupport (5.0.0.rc1) lib/active_support/core_ext/benchmark.rb:12:in `ms'
  actionpack (5.0.0.rc1) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
  actionpack (5.0.0.rc1) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
  activerecord (5.0.0.rc1) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
  actionpack (5.0.0.rc1) lib/action_controller/metal/instrumentation.rb:43:in `render'
  responders (2.2.0) lib/action_controller/responder.rb:238:in `default_render'
  responders (2.2.0) lib/action_controller/responder.rb:170:in `to_html'
  responders (2.2.0) lib/action_controller/responder.rb:163:in `respond'
  responders (2.2.0) lib/action_controller/responder.rb:156:in `call'
  responders (2.2.0) lib/action_controller/respond_with.rb:205:in `respond_with'
  devise (4.1.1) app/controllers/devise/sessions_controller.rb:12:in `new'
  actionpack (5.0.0.rc1) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
  actionpack (5.0.0.rc1) lib/abstract_controller/base.rb:181:in `process_action'
  actionpack (5.0.0.rc1) lib/action_controller/metal/rendering.rb:30:in `process_action'
  actionpack (5.0.0.rc1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (5.0.0.rc1) lib/active_support/callbacks.rb:126:in `call'
  activesupport (5.0.0.rc1) lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
  activesupport (5.0.0.rc1) lib/active_support/callbacks.rb:455:in `call'
  activesupport (5.0.0.rc1) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
  activesupport (5.0.0.rc1) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
  activesupport (5.0.0.rc1) lib/active_support/callbacks.rb:90:in `run_callbacks'
  actionpack (5.0.0.rc1) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (5.0.0.rc1) lib/action_controller/metal/rescue.rb:31:in `process_action'
  actionpack (5.0.0.rc1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (5.0.0.rc1) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (5.0.0.rc1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  activesupport (5.0.0.rc1) lib/active_support/notifications.rb:164:in `instrument'
  actionpack (5.0.0.rc1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (5.0.0.rc1) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
  activerecord (5.0.0.rc1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (5.0.0.rc1) lib/abstract_controller/base.rb:126:in `process'
  actionview (5.0.0.rc1) lib/action_view/rendering.rb:30:in `process'
  actionpack (5.0.0.rc1) lib/action_controller/metal.rb:190:in `dispatch'
  actionpack (5.0.0.rc1) lib/action_controller/metal.rb:262:in `dispatch'
  actionpack (5.0.0.rc1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
  actionpack (5.0.0.rc1) lib/action_dispatch/routing/route_set.rb:32:in `serve'
  actionpack (5.0.0.rc1) lib/action_dispatch/routing/mapper.rb:16:in `block in <class:Constraints>'
  actionpack (5.0.0.rc1) lib/action_dispatch/routing/mapper.rb:46:in `serve'
  actionpack (5.0.0.rc1) lib/action_dispatch/journey/router.rb:39:in `block in serve'
  actionpack (5.0.0.rc1) lib/action_dispatch/journey/router.rb:26:in `each'
  actionpack (5.0.0.rc1) lib/action_dispatch/journey/router.rb:26:in `serve'
  actionpack (5.0.0.rc1) lib/action_dispatch/routing/route_set.rb:725:in `call'
  actionview (5.0.0.rc1) lib/action_view/digestor.rb:12:in `call'
  warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.6) lib/warden/manager.rb:34:in `catch'
  warden (1.2.6) lib/warden/manager.rb:34:in `call'
  rack (2.0.0.rc1) lib/rack/etag.rb:25:in `call'
  rack (2.0.0.rc1) lib/rack/conditional_get.rb:25:in `call'
  rack (2.0.0.rc1) lib/rack/head.rb:12:in `call'
  rack (2.0.0.rc1) lib/rack/session/abstract/id.rb:222:in `context'
  rack (2.0.0.rc1) lib/rack/session/abstract/id.rb:216:in `call'
  actionpack (5.0.0.rc1) lib/action_dispatch/middleware/cookies.rb:613:in `call'
  activerecord (5.0.0.rc1) lib/active_record/migration.rb:552:in `call'
  actionpack (5.0.0.rc1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
  activesupport (5.0.0.rc1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
  activesupport (5.0.0.rc1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
  activesupport (5.0.0.rc1) lib/active_support/callbacks.rb:90:in `run_callbacks'
  actionpack (5.0.0.rc1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
  actionpack (5.0.0.rc1) lib/action_dispatch/middleware/executor.rb:12:in `call'
  actionpack (5.0.0.rc1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  actionpack (5.0.0.rc1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
  web-console (3.3.0) lib/web_console/middleware.rb:131:in `call_app'
  web-console (3.3.0) lib/web_console/middleware.rb:28:in `block in call'
  web-console (3.3.0) lib/web_console/middleware.rb:18:in `catch'
  web-console (3.3.0) lib/web_console/middleware.rb:18:in `call'
  actionpack (5.0.0.rc1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
  railties (5.0.0.rc1) lib/rails/rack/logger.rb:36:in `call_app'
  railties (5.0.0.rc1) lib/rails/rack/logger.rb:24:in `block in call'
  activesupport (5.0.0.rc1) lib/active_support/tagged_logging.rb:70:in `block in tagged'
  activesupport (5.0.0.rc1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (5.0.0.rc1) lib/active_support/tagged_logging.rb:70:in `tagged'
  railties (5.0.0.rc1) lib/rails/rack/logger.rb:24:in `call'
  quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
  actionpack (5.0.0.rc1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
  rack (2.0.0.rc1) lib/rack/method_override.rb:22:in `call'
  rack (2.0.0.rc1) lib/rack/runtime.rb:22:in `call'
  activesupport (5.0.0.rc1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  actionpack (5.0.0.rc1) lib/action_dispatch/middleware/executor.rb:12:in `call'
  actionpack (5.0.0.rc1) lib/action_dispatch/middleware/static.rb:136:in `call'
  rack (2.0.0.rc1) lib/rack/sendfile.rb:111:in `call'
  railties (5.0.0.rc1) lib/rails/engine.rb:522:in `call'
  puma (3.4.0) lib/puma/configuration.rb:224:in `call'
  puma (3.4.0) lib/puma/server.rb:569:in `handle_request'
  puma (3.4.0) lib/puma/server.rb:406:in `process_client'
  puma (3.4.0) lib/puma/server.rb:271:in `block in run'
  puma (3.4.0) lib/puma/thread_pool.rb:114:in `block in spawn_thread'

Started POST "/__better_errors/31d37489ea7d85b0/variables" for ::1 at 2016-06-28 13:38:54 -0600

【问题讨论】:

  • 你能添加回溯吗?
  • 肯定是有问题的更新
  • 您的form_for(@user, :url =&gt; admins_create_user_path 没有右括号。
  • 尼克,添加为答案并错误地奖励最佳......我的愚蠢错误。
  • 不介意我这样做:)

标签: ruby-on-rails twitter-bootstrap ruby-on-rails-4 erb


【解决方案1】:

您的 form_for(@user, :url =&gt; admins_create_user_path 没有右括号。

【讨论】:

    【解决方案2】:

    您缺少右括号:

    <%= form_for(@user, :url => admins_create_user_path do |f| %>
    

    应该是:

    <%= form_for(@user, :url => admins_create_user_path) do |f| %>
    

    【讨论】:

      猜你喜欢
      • 2011-05-08
      • 2021-06-16
      • 1970-01-01
      • 2012-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-10
      相关资源
      最近更新 更多