简体   繁体   English

Rails 3.1 response_with在生产中不起作用

[英]Rails 3.1 respond_with does not work in production

I have a view folder that contains many js.coffee files that are called when various controller actions are executed. 我有一个视图文件夹,其中包含许多在执行各种控制器操作时都会调用的js.coffee文件。 It is called when a remote form is submitted and is triggered in the controller by the respond_with line. 提交远程表单时调用该方法,并在控制器中由response_with行触发。 I'm giving the create method as an example. 我以create方法为例。 It's important to note that all of this works PERFECTLY in development mode. 重要的是要注意,所有这些功能都可以在开发模式下正常运行。 In production, I've made sure I've precompiled my assets, ran bundle install --deployment etc. 在生产中,我确保已经预编译了我的资产,运行了bundle install --deployment等。

users_controller.rb users_controller.rb

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

  if @user.save
    respond_with @user, :location => users_url    #This line is throwing the error in production
  end
end

The following Jquery should be executed after the the record is saved and does so perfectly in development mode. 保存记录后,应执行以下Jquery,并且在开发模式下可以完美执行。 It is important to note that the record is created, however the following file is never executed 重要的是要注意,记录已创建,但是以下文件从未执行

create.js.coffee create.js.coffee

$('#errors').empty()
$('#errors').show()
<% if @user.errors.any? %>
  $('<%= escape_javascript(render :partial => "errors", :locals => {:target => @user })%>')
  .appendTo('#errors')
<% else %>
  $('<%= escape_javascript(render(:partial => @user))%>')
  .appendTo('#user_table')
  .hide()
  .fadeIn(200)
  $('#errors').hide()
  $('#new_user')[0].reset()
  $('#users_count').html '<%= users_count %>'
<% end %>
$('#error_close').click ->
$('#errors').fadeOut()

This is the error that is being thrown in production. 这是在生产中引发的错误。

ActionView::MissingTemplate (Missing template users/create, application/create with {:locale=>[:en], :formats=>[:js, :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"
):
app/controllers/users_controller.rb:19:in `create'

I figured it out finally. 我终于想通了。 Take coffee-rails and uglifier out of the :assets group and that fixes the problem. 从:assets组中取出coffee-rails和uglifier,这可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM