gpt4 book ai didi

javascript - 需要重新加载我的页面才能使用 Rails 查看某些元素

转载 作者:行者123 更新时间:2023-12-03 08:35:43 26 4
gpt4 key购买 nike

我目前正在从事一个大学项目,我必须使用 Rails 部署一个网页。在 Rails 中使用 Materialise Css,在表单上,​​元素“Select”起作用的唯一方法是重新加载页面,对于其他 javascript 来说,它们似乎只能重新加载页面......现在我正在使用“脚本” “一旦页面重新加载,但这完全是一种糟糕的做法

这里有 Application.js

//= require jquery
//= require jquery.turbolinks

//= require jquery_ujs
//= require materialize-sprockets
//= require_tree .

//= require turbolinks

gem 文件

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]

应用程序.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?

最佳答案

如果没有 Turbolink,问题仍然会发生吗?我也遇到过类似的情况,我通过最初删除它来解决。我意识到这不是一个完整的解决方案,但我希望可能会为您指明正确的方向。

这里有更多信息:Rails 4: how to use $(document).ready() with turbo-links

关于javascript - 需要重新加载我的页面才能使用 Rails 查看某些元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33224658/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com