【问题标题】:rails 3.2 ActionView MissingTemplate only in productionrails 3.2 ActionView MissingTemplate 仅在生产中
【发布时间】:2012-02-07 08:56:52
【问题描述】:

我有一个在开发模式下运行良好的应用程序。在尝试在 Webrick 或Passenger/apache 中进行生产测试时,我的大多数站点都加载得很好,直到我尝试提交一个ajax 表单。我已经正确使用了 bundle install --deployment。我已经正确地预编译了我的资产。但由于某种原因,我在提交远程表单时收到以下错误。请记住,ajax 实际上正在工作,因为它正在数据库中创建记录。我发现有趣的一件事是我正在使用带有 ruby​​ 1.9.3 的 gemset,但是在这些错误代码中我得到了对 ruby​​ 1.9.1 的引用。我还包括用户控制器,因此您可以看到控制器引用。救命!

更新!!取决于是什么操作,无论是创建操作、编辑操作更新操作还是销毁错误缺少模板 users/create 或 users/update 或 users/edit users/destroy 等. 阅读对第一个答案的评论,因为我认为这是预编译过程中未包含 javascript 文件的问题。

Started GET "/users/5" for 24.163.20.124 at 2012-02-07 03:30:09 -0500
Processing by UsersController#show as HTML
  Parameters: {"id"=>"5"}
Completed 500 Internal Server Error in 58ms

ActionView::MissingTemplate (Missing template users/show, application/show with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder]}. Searched in:
* "/home/ctilley/Development/RatatouilleCatering/app/views"
* "/home/ctilley/Development/RatatouilleCatering/vendor/bundle/ruby/1.9.1/gems/wash_out-0.3.1/app/views"
* "/home/ctilley/Development/RatatouilleCatering/vendor/bundle/ruby/1.9.1/gems/ckeditor-3.7.0.rc2/app/views"
):
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0/lib/action_view/path_set.rb:58:in `find'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0/lib/action_view/lookup_context.rb:109:in `find'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0/lib/action_view/renderer/abstract_renderer.rb:3:in `find_template'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0/lib/action_view/renderer/template_renderer.rb:28:in `determine_template'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0/lib/action_view/renderer/template_renderer.rb:10:in `render'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0/lib/action_view/renderer/renderer.rb:36:in `render_template'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0/lib/action_view/renderer/renderer.rb:17:in `render'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0/lib/abstract_controller/rendering.rb:109:in `_render_template'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0/lib/action_controller/metal/streaming.rb:225:in `_render_template'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0/lib/abstract_controller/rendering.rb:103:in `render_to_body'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0/lib/action_controller/metal/renderers.rb:28:in `render_to_body'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0/lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0/lib/abstract_controller/rendering.rb:88:in `render'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0/lib/action_controller/metal/rendering.rb:16:in `render'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0/lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.0/lib/active_support/core_ext/benchmark.rb:5:in `block in ms'

控制器/users_controller.rb

class UsersController < ApplicationController

  before_filter :require_user
  respond_to :html, :js
  load_and_authorize_resource
def index
  @users = User.search(params[:search]).order(sort_column + " " + sort_direction).paginate(:per_page => 10, :page=>params[:page])

   authorize! :read, @article
end

def show
end

def create
  @user = User.new(params[:user])

  if @user.save
  respond_with @user, :location => users_url
  end
end

def destroy
  @user = User.find(params[:id])
  @user.destroy

  respond_with @user, :location => users_url
end

def edit
  @user = User.find(params[:id])
  respond_with @user, :location => users_url
end

def update
  @user = User.find(params[:id])
  @user.update_attributes(params[:user])

  respond_with @user, :location => users_url
end
private
def sort_column
  params[:sort] || "id"
end
def sort_direction
   params[:direction] || "asc"
 end

end

【问题讨论】:

    标签: ruby-on-rails-3.1 asset-pipeline production-environment ruby-on-rails-3.2


    【解决方案1】:

    将以下内容移出 Gemfile 中的资产组

    gem 'coffee-rails', "~> 3.2.1"
    gem 'uglifier', ">= 1.0.3"
    

    【讨论】:

    • 非常感谢您的回答。我被难住了。
    • 对此有何解释?
    • @Lyudmil 我不知道。它只在这个特定版本中影响了我
    【解决方案2】:
    ActionView::MissingTemplate (Missing template users/show...)
    

    这意味着缺少视图文件 app/users/show.html.erb。在这里创建一个虚拟文件,看看是否能解决问题。

    【讨论】:

    • 似乎并非如此。 respond_with 语句强制对索引执行这些操作。如上所述,所有这些在开发模式下都非常有效。编辑、更新、创建是调用对应的 index.js.coffee create.js.coffee update.js.coffee 和 destroy.js.coffee 的远程表单。它们位于该特定控制器的视图文件夹中。我在想的是这些 javascript 文件在预编译过程中没有被编译。因此记录已发布,但 javascript 未执行。我需要找到一种方法将这些文件添加到资产/预编译路径。
    猜你喜欢
    • 1970-01-01
    • 2016-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-03
    • 1970-01-01
    • 2011-11-10
    相关资源
    最近更新 更多