Tag: javascript

Google地图 – 将其设置为与Rails 5一起使用 – 地理编码器不进行地理编码

我已经尝试了4年多来尝试找出在我的Rails应用程序中使用谷歌地图的方法。 我目前正在尝试使用Rails 5。 我最近发布了这个呼救声。 我收到的建议对我没有用,所以我现在再试一次,看看别人是否知道一些事情。 Rails 5,Gmaps4Rails – 设置 我有组织和地址的模型。 协会是: 组织 has_many :addresses, as: :addressable accepts_nested_attributes_for :addresses, reject_if: :all_blank, allow_destroy: true 地址 belongs_to :addressable, :polymorphic => true, optional: true 我不再试图用gmaps4rails gem来解决这个问题了。 我从我的gem文件中删除了它。 我仍然有地理编码器gem。 在我的地址控制器中,我有 def index @addresses = Address.all end def show end 在我的组织控制器中,我有 def index @organisations = Organisation.all authorize @organisations end def show […]

Facebook API错误100 – 链接无效

我正在使用Facebook API在我的Rails应用程序中创建发送对话框。 我只是使用Facebook推荐的Javascript格式(作为HTML中的脚本)。 我的问题是我得到了: API Error code 100, invalid parameter, link URL not properly formatted 在以下方面: function detail(friend_id, user_name, restaurant_name, restaurant_id, articles){ // assume we are already logged in FB.init({appId: ”, xfbml: true, cookie: true}); FB.ui({ to: friend_id, method: ‘send’, name: user_name +’ needs more details about ‘+ restaurant_name, picture: ‘http://sofzh.miximages.com/javascript/fb-logo-75.png’, link: “restaurants/”+restaurant_id, description: ”+user_name […]

在Heroku的Rails应用程序中包含两次jQuery

我的问题类似于其他一些问题,但仍然没有为我的情况提供答案 我在Gemfile中的应用程序中包含了jQuery gem: gem ‘jquery-rails’ 在application.js中: //= require jquery //= require jquery-ui //= require jquery_ujs … //= require_tree . 我的development.rb有 # Do not compress assets config.assets.compress = false # Expands the lines which load the assets config.assets.debug = true 我的资产没有预先编译,没有公共/资产。 一切都在当地运行良好。 但是当我推送到heroku时,我会在页面上包含不同的application.js文件。 它不是一个清单文件,而是缩小了jQuery的版本。 因此我将jQuery包含两次。 以下是我的网页源代码: … 当我点击/assets/application.js?body=1我看到了缩小的jQuery。 当我在本地运行我的应用程序并单击/assets/application.js?body=1我只看到清单。 我试图添加到development.rb config.serve_static_assets = false 它没有帮助。 我还清理了多次资产和缓存。 唯一对我有用的是设定 […]

Rails Paperclip和AJAX表单

我有一个包含表单的模式,用户可以在其中上传照片。 正确上传照片后,我想通过Ajax响应并显示消息。 不幸的是,表单是以HTML格式提交的,而不是JS格式的。 任何的想法? 表格代码: {:controller => ‘objects’, :action => ‘create’}, :remote=> true, :html => { :multipart => true }) do |f| %> Upload 谢谢

在使用带有Rails的Select2插件时未定义$,未捕获的ReferenceError

我正在尝试使用Select2插件向我的选择框添加搜索栏。 查看页面控制台时出现以下错误: 未捕获的ReferenceError:$未定义 在这里搜索不同的问题让我相信这个错误发生是因为在调用脚本之前没有包含或放置jQuery javascript。 但我仍然找不到让它发挥作用的方法。 如何修复此错误并使select2插件正常工作? 这是application.js文件: //= require jquery //= require jquery_ujs //= require jquery-ui //= require jquery-fileupload/basic //= require jquery-fileupload/vendor/tmpl //= require select2 //= require tinymce //= require turbolinks //= require_tree 我已经尝试以许多不同的方式在application.js文件中重新排列select2的顺序但没有成功(我试图确保在Select2之前加载jQuery)。 这是index.html.haml文件: %select{:id => “test”} – @lamps.each do |lamp| %option{:value => “1”}= lamp.brand + ‘ ‘ + lamp.category + ‘ ‘ […]

使用连接表元数据创建Rails 4表单

非常新的Rails 4开发人员。 我有一个用户正在创建练习的表单。 练习可以有很多设备,而设备可以是可选的(想想俯卧撑是做俯卧撑)。 我将此“可选”字段存储在连接表exercise_equipment中。 我无法获取参数来实际发送我选择的集合元素的值。 请参阅下面的模型,视图,控制器和参数。 以下是我的模型的属性/关系: # id :integer # name :string # is_public :boolean Exercise has_many :exercise_equipment has_many :equipment, :through => :exercise_equipment accepts_nested_attributes_for :exercise_equipment # id :integer # exercise_id :integer # equipment_id :integer # optional :boolean ExerciseEquipment belongs_to :exercise belongs_to :equipment accepts_nested_attributes_for :equipment # id :integer # name :string Equipment has_many :exercise_equipment […]

一次只允许一个用户编辑内容

例如,如果您想编辑client-site.com/pages/5 ,请转到admin-site.com/pages/5/edit 。 我想让一个管理员一次访问admin-site.com/pages/5/edit 。 我计划做的是在数据库中创建“editor_id”和“editing_rights_expiration_time”列,并使用JavaScript /服务器端逻辑更新它们。 有没有更好的方法来实现此function? 我正在使用Rails 3。

Rails 5 + Ajax:仅在注释存在时附加注释

我正在尝试创建一个function,用户可以使用Ajax创建对文章的评论。 但是,我无法理解为什么只有一条评论存在才能通过ajax成功呈现评论。 注释将提交到数据库而不进行任何回滚。 如果我重新加载页面并创建第二条评论,则只会附加新评论。 Started POST “/articles/veniam-ipsum-eos-quas-aut-rerum-consequatur-at-velit-perferendis-odio/comments” for 103.252.202.198 at 2017-11-03 16:50:14 +0000 Processing by CommentsController#create as JS Parameters: {“utf8″=>”✓”, “comment”=>{“content”=>”comment only appended if a comment exists”}, “commit”=>”Add Comment”, “article_id”=>”veniam-ipsum-eos-quas-aut-rerum-consequatur-at-velit-perferendis-odio”} User Load (0.4ms) SELECT “users”.* FROM “users” WHERE “users”.”id” = $1 ORDER BY “users”.”id” ASC LIMIT $2 [[“id”, 1], [“LIMIT”, 1]] Article Load (0.6ms) SELECT […]

如何使用RSpec测试javascript重定向?

我正在使用xhr:post与控制器交互,我期待重定向。 在js.erb中我有window.location.href =地址。 手动测试,浏览器可以正确重定向。 我如何使用RSpec进行测试? response.should redirect_to失败

如何正确地将嵌入式ruby代码放入JavaScript中?

我试图在JavaScript中嵌入Ruby代码的输出: var stuff= “”; 嵌入式部分正在单独工作,显示如下结果: { “name”:”John Johnson”, “street”:”Oslo West 555″, “age”:33, “phone”:”555 1234567″} 以上这一行是精确的页面来源; 它虽然在本地运行,所以我无法向您显示该页面。 在变量中,我尝试将其发送到我的应用程序: document.getElementById(“X_Axis”).value=stuff.name; 通过输入: 我每次都得到一个undefined值。 我尝试在JavaScript中对代码进行硬编码,并且它工作得很好,当嵌入式Ruby放入JavaScript变量时,它总是给我undefined值。