Error in Rails 3.1 using js jQuery - “Template is missing”

别说谁变了你拦得住时间么 提交于 2019-12-08 07:46:44

问题


I created app according to this post http://stjhimy.com/posts/7-creating-a-100-ajax-crud-using-rails-3-and-unobtrusive-javascript , but get an error:

Missing template posts/create, application/create with {:handlers=>[:erb, :builder, :coffee, :haml], :formats=>[:html], :locale=>[:en, :en]}. Searched in: * "/home/ember/Projects/test_app/app/views"

Maybe in Rails 3.1 actions render something by default. Besides, there no format js (:formats=>[:html]). But i can`t find any about this.

When i doing like this:

  respond_to do |format|
    format.js {render :content_type => 'text/javascript'}
  end

or without content_type - browser redirects to empty page. In this case:

  respond_to do |format|
    format.js
    format.html {render :nothing => true}
  end

browser shows the same empty page. How can i do that without any redirects?

Maybe it`s old method?


回答1:


Posting the answer you arrived at here so others will know:

With Rails 3.1, you no longer need to manually include the rails.js file in your application (or the jquery.js file for that matter). Having gem 'jquery-rails' in your Gemfile will already include these for you.

When you do manually include old pre-Rails 3.1 versions of these files, it could interfere with proper javascript/jQuery functionality.




回答2:


Try adding the jquery-rails gem to your Gemfile.



来源:https://stackoverflow.com/questions/7101822/error-in-rails-3-1-using-js-jquery-template-is-missing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!