Tag: ruby on rails

如何使用JQuery将样式应用于正确的标记

我正在尝试为我的代码添加更多逻辑,但它不起作用。 我必须在span标签周围包裹我的图标,以便正确地获得行高。 我正在使用谷歌字体: html.erb favorite_border Add Wishlist <input type="hidden" class="wish-cls" value="” /> SCSS … span.wish-flex{ display: inline-flex; vertical-align: middle; padding-top: 10px } .material-icons.red { color: $hotRed; } span .material-icons{ margin-top: -2px } JavaScript的 $(“[data-id=wish]”).click(function(e){ e.preventDefault(); var value = $(this).next(“.wish-cls”).val(); console.log(“Clicked: ” + value); /* Applying the css when clicked * * We use toggleClass instead […]

jquery文件上传rails“错误清空文件上传结果”

我有这样的观点(forms偏): = javascript_include_tag ‘car_photos’ = stylesheet_link_tag(‘jquery.fileupload-ui’) = form_for @car do |f| – if @car.errors.any? #error_explanation %h2= “Ошибки в полях: #{pluralize(@car.errors.count, “error”)}” %ul – @car.errors.full_messages.each do |msg| %li= msg .tab#car-data{style: “height: 1290px;”} .field = f.label :manufacturer_id, “Марка” = f.select(:manufacturer_id, options_from_collection_for_select(VehicleManufacturer.all, :id, :name, @car.manufacturer_id), {}, :prompt => “Выберите марку”, required: true, id: “manufacturer-select”) .field = f.label :model_id, […]

如何在ajax url中调用控制器动作

我想调用ajax url中的控制器方法,根据另一个下拉列表中的值动态填充下拉列表。 我得到的值是字符串,当我使用ajax url调用此方法时,它总是引用’show’方法。 我的ajax电话 $(‘#users’).change(function() { url: ‘/users/update_groups’, data: {name: $(this).val()}, success: function (data) { alert(data); } }); 在我的users_controller.rb中 def update_groups user_name # returns list of groups end 如何使用ajax url调用此方法?

Rails ajax表单不是从另一个内部提交的

我有一个Rails 3.2 ajax表单,为酒店创建了一个新房间。 新的Room ajax表单在Room索引页面上正常工作,但是一旦我在Hotel编辑页面上嵌入了新的Room ajax表单,表单就会正常提交而不使用Ajax。 要创建新的Room表单,请使用Hotel edit.html.erb页面上的以下链接: @hotel.id), :remote => true, :class => ‘new_room’ %> 这会将以下表单部分加载到同一页面: true, :html => { :class => “remote-form” } do |f| %> @hotel_id %> ‘room_create’ %> “room_cancel” %> 最后,我在create.js.erb(在rooms文件夹中)中有以下内容: alert(‘Test creating a room’); var content = $(”); $(“#room_list tbody”).append(content); 没有执行create.js.erb并定期提交表单(非ajax),我终于到达了show.html.erb页面。 为什么表单在单位索引页面上正常工作,而不是在相关的酒店编辑页面上?

jQuery自动完成function在Rails 4中不起作用

我正在尝试在我的Rails 4.0应用程序中集成jQuery UI Autocomplete,就像在这个Railscast: 102-AutoCompleteAssociationRevised中描述的那样。 不幸的是,自动完成function不起作用。 虽然呈现的HTML看起来很好,但我没有得到任何建议: 我也停用了Turbolinks,但没有改变…… 在我的Gemfile中,我包含了gem’jquery gem ‘jquery-ui-rails’ ,我的application.js看起来像这样: //= require jquery //= require jquery.ui.all //= require jquery_ujs //= require bootstrap //= require turbolinks //= require jquery-fileupload/basic //= require jquery-fileupload/vendor/tmpl //= require_tree . 这是我正在使用的forms, edit.html.erb : autocomplete.js.coffee: autocomplete = -> $(‘#plan_part_name’).autocomplete source: $(‘#plan_part_name’).data(‘autocomplete-source’) $(document).ready(autocomplete) $(document).on(‘page:load’, autocomplete)

jquery:安装在Rails中不起作用

我在Rails 3.1 app中安装了gem jquery-rails 。 但是下面的行 rails generate jquery:install –ui 得到错误: Could not find generator jquery:install.

为什么这个DateParser在Safari中不起作用?

我渲染这个JSON对象: [{“created_at”:”2010-09-21T20:41:28Z”,”subject”:”hello world”}] 然后我使用这个日期解析器来解析它(见下文),但它只适用于Chrome 6.0.4,Firefox 3.6.8,但不适用于Safari 5.0.2 —我收到NaN错误。 是什么赋予了? Date.prototype.toRelativeTime = function(now_threshold) { var delta = new Date() – this; now_threshold = parseInt(now_threshold, 10); if (isNaN(now_threshold)) { now_threshold = 0; } if (delta ms second: 1000, // ms -> sec minute: 60, // sec -> min hour: 60, // min -> hour day: 24, // […]

如何从erb模板调用JavaScript函数?

如果您定义JavaScript函数然后从erb模板调用它,则不会调用该函数。 为什么? 单击此链接应显示警报,但不会显示。 = link_to “Add Sprout”, new_sprout_path, remote: true 控制器: def new @sprout = Sprout.new respond_to { |format| format.js } end 然后在模板中我调用一个函数: # sprouts/new.js.erb doSomething(); 该函数在我的js文件中定义: # javascripts/sprouts.js.coffee doSomething = -> alert “yum ghum I am a new sprout.” JavaScript回来了。 我可以在控制台中看到它。 但我看不到警报。 为什么这不起作用? 我正在使用Rails 4。

在JavaScript函数中插入多行字符串作为变量

我想通过RJS插入一个取自textarea的多行字符串。 这样做: $(‘#description’).text(”); 不起作用,因为它会生成这样的东西: $(‘#description’).text(‘first line second line fourth line’); 因为字符串不在一行上,所以JS调用失败。 那么现在simple_format正确地格式化了字符串,我怎样才能将它全部打印在我的RJS文件中的一行?

Rails 3 – 包括View上的JavaScript?

这就是我正在尝试做的事情….当用户登录并重定向到登录页面时,我想运行一些jquery ajax来抓取并注入一些内容。 我最初在我的application.js文件中有它,但问题是代码存在于没有登录的用户,这意味着我必须添加逻辑来解决看起来不干净的问题。 我想要的是调用视图以便能够包含JavaScript ….我尝试在视图文件中粘贴它但是失败了,因为它是在页面底部的JQUERY之前加载的。 。 Rails 3大师如何处理这个问题? 谢谢!