我目前正在开展大学项目,我必须使用Rails部署网页。 使用Materialise Css for rails,在表单上,“Select”元素工作的唯一方法是重新加载页面,对于其他javascripts,它们似乎只能重新加载页面...现在我正在使用“脚本” “这会重新加载一次页面,但它完全是一个糟糕的练习
这里有Application.js
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require materialize-sprockets
//= require_tree .
//= require turbolinks
gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.4'
# Use sqlite3 as the database for Active Record
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
#gem 'pg', group: :production
#gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
gem 'jquery-turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'hirb'
gem 'carrierwave'
#gem 'bootstrap-sass', '~> 3.3.0'
gem 'devise'
gem 'rolify'
gem 'cancan'
gem 'will_paginate'
gem 'will_paginate-bootstrap'
#gem "twitter-bootstrap-rails"
gem 'therubyracer', :platform => :ruby
gem 'materialize-sass'
gem 'rails_12factor', group: :production
gem 'puma'
gem 'cloudinary'
#gem 'libv8', '3.11.8.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
applications.scss
@import "materialize";
最后是_form
<script>
$(document).ready(function() {
$('select').material_select();
});</script>
<div class="container">
<%= form_for @articulo, :html =>{:multipart => true} do |f| %>
<div class="row">
<div class="input-field col s6">
<%= f.text_field :nombre%>
<label for="first_name">Nombre del producto</label>
</div>
<div class="input-field col s6">
<%= f.text_field :ubicacion%>
<label for="ubicacion">Ubicación</label>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<label for="precio">Precio $</label>
<%=f.text_field :precio, :class => 'text_field', :min => 0, :step => 0.01, required: true%>
</div>
</div>
<div class="file-field input-field">
<div class="btn">
<span>Imagen</span><input type="file">
<%= f.file_field :foto %>
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
</div>
<div class="row">
<div class="input-field col s12">
<%= f.text_field :descripcion, :class=> "materialize-textarea"%>
<label for="textarea1">Descripción</label>
</div>
</div>
<div class="row">
<div class="col s6" id="category_id">
<%= f.label :category_id, 'Categoría' %>
<%= collection_select(:article, :category_id, Category.where(eliminado: false).all , :id, :nombre,class: "browser-default") %>
</div>
</div>
<br>
<%= f.submit "Publicar", class: 'btn ' %><%end%>
</div>
-------编辑------ 我已经解决了这个问题;在本地工作,但当我上传到Heroku时,发生相同的...任何解决方案?或者我怎么能更新heroku中的gemfile?
答案 0 :(得分:1)
没有turbolinks问题是否仍然存在?我有类似的情况,我通过最初删除它解决了。我意识到这不是一个完整的解决方案,但可能会指出你正确的方向。
此处有更多信息:Rails 4: how to use $(document).ready() with turbo-links