Rails 请教 Rails 5 是否支持 Haml,发现 升级到 Rails 报错

eric_chao · 2016年09月12日 · 最后由 gwq 回复于 2017年03月29日 · 2967 次阅读

... ActionController::UnknownFormat (SessionsController#new is missing a template for this request format and variant.

request.formats: ["text/html"] request.variant: []

NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you're loading it in a web browser, we assume that you expected to actually render a template, not… nothing, so we're showing an error to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a shot.): ...

Gemfile: ... source :gemcutter

gem 'rails', '5.0.0.1'

bundler requires these gems in all environments

gem 'aasm' gem 'acts_as_tree' gem 'awesome_print' gem 'compass' gem 'haml-rails' ...... ... 切换到 erb,没问题

你的 gemfile 有没有 haml 这个 gem? haml-rails 貌似只是提供 generator 的功能? 如果有的话,更新一下 haml, 或者使用 github 上版本?

支持,一支在用,没发现啥问题。

Using Haml with Rails To use Haml with Rails, simply add Haml to your Gemfile and run bundle. gem 'haml' Haml 5 will require Rails version 4.0 or later. If you are using Rails 3.x, you should use Haml version 4.0.x: gem 'haml', '~> 4.0.5' If you'd like to replace Rails's Erb-based generators with Haml, add haml-rails to your Gemfile as well.

看一下 Gemfile.lock 的 haml 的依赖,是否是旧了。

haml 一直有,上面没有贴 ... *** LOCAL GEMS ***

aasm (4.11.0) actioncable (5.0.0.1) actionmailer (5.0.0.1, 4.2.7) actionpack (5.0.0.1, 4.2.7.1, 4.2.7) actionview (5.0.0.1, 4.2.7.1, 4.2.7) activejob (5.0.0.1, 4.2.7) activemodel (5.0.0.1, 4.2.7) activemodel-serializers-xml (1.0.1) activerecord (5.0.0.1, 4.2.7) activerecord-oracle_enhanced-adapter (1.7.1, 1.5.6, 1.4.3) activesupport (5.0.0.1, 4.2.7.1, 4.2.7) acts_as_reportable (1.1.1) acts_as_tree (2.5.1) acts_as_votable (0.10.0) arel (7.1.1, 6.0.3) awesome_print (1.7.0) bcrypt (3.1.11) bigdecimal (1.2.8) builder (3.2.2) bundle (0.0.1) bundler (1.13.0, 1.12.5) byebug (9.0.5) choice (0.2.0) chronic (0.10.2) chunky_png (1.3.7) climate_control (0.0.3) cocaine (0.5.8) coffee-rails (4.2.1) coffee-script (2.4.1) coffee-script-source (1.10.0) color (1.8) compass (1.0.3) compass-core (1.0.3) compass-import-once (1.0.5) concurrent-ruby (1.0.2) devise (4.2.0) did_you_mean (1.0.2, 1.0.0) dynamic_form (1.1.4) enumerize (2.0.0) erubis (2.7.0) execjs (2.7.0) fastercsv (1.5.5) ffi (1.9.14) font-awesome-rails (4.6.3.1) globalid (0.3.7) haml (4.1.0.beta.1, 4.0.7) haml-contrib (1.0.0.1) haml-rails (0.9.0) hashie (3.4.4) html2haml (2.0.0) i18n (0.7.0) io-console (0.4.6, 0.4.5) jquery-rails (4.2.1) jquery-ui-rails (5.0.5) json (2.0.2, 1.8.3) kaminari (0.17.0) loofah (2.0.3) mail (2.6.4) method_source (0.8.2) mime-types (3.1) mime-types-data (3.2016.0521) mimemagic (0.3.2) mini_portile2 (2.1.0) minitest (5.9.0, 5.8.3) multi_json (1.12.1) mysql2 (0.4.4) nested_form (0.3.2) net-telnet (0.1.1) nio4r (1.2.1) nokogiri (1.6.8) omniauth (1.3.1) orm_adapter (0.5.0) paper_trail (5.2.2, 5.2.1) paperclip (5.1.0) pdf-writer (1.1.8) pkg-config (1.1.7) power_assert (0.3.1, 0.2.6) pr_geohash (1.0.0) protected_attributes (1.1.3) psych (2.1.1, 2.0.17) quiet_assets (1.1.0) rack (2.0.1, 1.6.4) rack-pjax (1.0.0, 0.8.0) rack-test (0.6.3) rails (5.0.0.1, 4.2.7) rails-controller-testing (1.0.1) rails-deprecated_sanitizer (1.0.3) rails-dom-testing (2.0.1, 1.0.7) rails-erd (1.5.0) rails-html-sanitizer (1.0.3) rails-observers (0.1.2) rails_admin (0.8.1) railties (5.0.0.1, 4.2.7.1, 4.2.7) rake (11.2.2, 10.4.2) rank (0.0.2) rb-fsevent (0.9.7) rb-inotify (0.9.7) rdoc (4.2.2, 4.2.1) remotipart (1.2.1) request_store (1.3.1) responders (2.3.0) rsolr (1.1.2, 1.0.13) ruby-graphviz (1.2.2) ruby-oci8 (2.2.2) ruby-plsql (0.6.0) ruby_parser (3.8.2) ruport (1.6.3) safe_yaml (1.0.4) sass (3.4.22) sass-rails (5.0.6) sexp_processor (4.7.0) sprockets (3.7.0) sprockets-rails (3.2.0) sunspot (2.2.6, 2.0.0.pre.130115) sunspot_rails (2.2.6, 2.0.0.pre.130115) sunspot_solr (2.2.6, 1.3.3) test-unit (3.2.1, 3.1.5) thor (0.19.1) thread_safe (0.3.5) tilt (2.0.5) transaction-simple (1.4.0.2) turbolinks (5.0.1) turbolinks-source (5.0.0) tzinfo (1.2.2) uglifier (3.0.2) warden (1.2.6) websocket-driver (0.6.4) websocket-extensions (0.1.2) whenever (0.9.7) will_paginate (3.1.0) ...

已找到的解决办法,application.rb 中,未加载 gem. Bundler.require(:default, Rails.env) if defined?(Bundler)

遇到同样的问题,但是你提供的方法对于我还是不行 eric_chao

需要 登录 后方可回复, 如果你还没有账号请 注册新账号