Tag: ruby on rails 4

容易出错的代码随机开始工作,但在刷新后再次破坏

我正在尝试安装“selectize-rails”gem。 我遇到了很多麻烦( TypeError:$(…)。selectize不是一个函数 )所以我放弃了一段时间并且处理不相关的事情。 然后我回到它,gem突然工作,虽然我改变的代码都没有与它相关。 然后,我更改了一行代码并刷新了页面以查看结果,并再次在之前的Web控制台中显示相同的错误: TypeError: $(…).selectize is not a function 之后,这就是我所做的一切:1)在文本编辑器中按“返回”以恢复更改,2)保存文档,3)刷新页面。 并且,错误仍然存​​在,尽管完全相同的代码仅在几秒钟前工作。 有谁知道这有可能吗? 这是不起作用的代码块,然后突然开始工作,然后再次停止: $(document).ready(function() { console.log( typeof $.fn.selectize === ‘function’); // true console.log( $(‘#select-to’).length === 1 ); // true var REGEX_EMAIL = ‘([a-z0-9!#$%&\’*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\’*+/=?^_`{|}~-]+)*@’ + ‘(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)’; $(‘#select-to’).selectize({ persist: false, maxItems: null, valueField: ’email’, labelField: ‘name’, searchField: [‘name’, ’email’], options: [ {email: ‘brian@thirdroute.com’, name: […]

过滤链停止为:doorkeeper_authorize! 渲染或重定向

我正在构建一个Rails API,目前正在使用门卫并设计使用ResourceOwnerFromCredentials流来validation用户。 一切正常,但我无法在Rspec中使用身份validation。 以下是如何在rspec中集成应用程序: let(:app_country) { FactoryGirl.create(:app_country)} let(:valid_attributes) { FactoryGirl.attributes_for(:app_city, {:app_country_id => app_country.id}) } let(:valid_session) { {:format => :json} } let(:application) { Doorkeeper::Application.create!(:name => “App HQ dashboard”, :redirect_uri => “https://localhost:3000/callback”) } let(:hq_user) { app_country.hq_users.create!(FactoryGirl.attributes_for :hq_user) } let(:token) { Doorkeeper::AccessToken.create! :application_id => application.id, :resource_owner_id => hq_user.id } 但每次我尝试测试受保护的操作时,测试都会失败,我从控制台获得以下输出: Filter chain halted as :doorkeeper_authorize! rendered or redirected […]

如何在rails迁移中将数据从一个表移动到另一个表?

我已经使用这些资源设置了一个rails网站: 用户(设计)作者 我已经意识到我需要将所有作者移到用户表中,因为我现在正在为这些用户设置角色作为作者。 目前我已经尝试了以下迁移,但没有任何工作,也没有数据传输到users表: class MoveAuthorsColumnDataToUsersTable author.name.downcase.gsub(‘ ‘,”), :encrypted_password => “”, :email => “”, :avatar_file_name => author.avatar_updated_at, :avatar_content_type => author.avatar_content_type, :avatar_file_size => author.avatar_file_size, :avatar_updated_at => author.avatar_updated_at, :role_id => “3” ) end end end 我在控制器中有一个带有属性的作者模型设置,我最终会将所有作者模型关系转移给用户。 author.rb模型: class Author { :large => “980×760”, :medium => “300×300>”, :thumb => “100×100>” }, :default_url => “/images/:style/missing.png” validates_attachment_content_type :avatar, :content_type => […]

为什么使用’gin’的add_index会创建一个’btree’索引呢?

我在PostgreSQL 9.3.4和Rails 4.0.4 。 我添加了一个“标签”列,以及相应的gin索引(或者,至少我要求一个)。 class AddTagsToPhotos < ActiveRecord::Migration def change add_column :photos, :tags, :text, array: true, null: false, default: [] add_index :photos, :tags, using: 'gin' end end 通过psqlvalidation结果: psql=# \d photos … tags | text[] | not null default ‘{}’::text[] Indexes: “index_photos_on_tags” btree (tags) 请注意,“标签”索引是btree类型 – 而我要求gin 。 现在手动创建一个索引以显示gin可用: psql=# create index index_photos_on_tags2 on […]

在Ruby on Rails应用程序中安装“nokogiri”时出错?

我一直在关注Lynda.com的Ruby on Rails课程。 我完成了video中提到的一切。 我正在尝试运行rails server命令,它应该默认为WEBrick,对吗? 我运行命令,它在nokogiri.rb文件和第29行有一个问题,其中发生错误这是读取的内容: require ‘nokogiri/nokogiri’ 这是我的命令提示符在运行rails server命令时呕吐的原因。 什么可能导致这个? 如果是这样,我需要运行什么命令来解决这个问题? 对我来说,这听起来像安装MySQL时错过了一些东西。 我不确定nokogiri是什么以及为什么rails server不会运行并指向该行代码。 此文件的路径是(Wherever you installed the folder to)\lib\ruby\gems\2.2.0\gems\nokogiri-1.6.6.2-x64-mingw32\lib 编辑**:我有一系列错误,比如它来自-long path-,from-longpath-等。 我尝试安装最新的gem,但没有成功。 是否有一个日志文件,我可以与您分享,以帮助找出问题。

基础和form_tag无效的jQuery UI datepicker

我是jQuery的初学者,我正在尝试实现一个datepicker。 我的Gemfile中有jquery-ui-rails gem。 我正在使用粉底,我的表格是: “date-field”) %> “date-field”) %> “button” %> 在application.js我有: //= require jquery //= require jquery_ujs //= require jquery-ui //= require foundation //= require_tree . $(function(){ $(document).foundation(); }); $(function() { $(‘.date-field’).datepicker(); }); 在application.css.scss我有: *= require_tree . *= require_self *= require foundation_and_overrides *= require jquery-ui */ @import “foundation_and_overrides”; 问题是我的文本字段保留为文本字段,单击它们时不会弹出日历。 在阅读完这个问题之后,我尝试停止我的服务器,运行bundle update ,然后运行bundle exec rake assets:precompile […]

Cocoon Gem:未定义的方法`new_record?’ for nil:link_to_remove_association上的NilClass

我正在尝试使用Cocoon Gem构建嵌套表单。 但是我得到的错误如下所示。 我发现Rails Cocoon Gem:Undefined Method’new_record? 在与Wicked的link_to_remove_association上 。 但是,从我的模型代码中可以看出,唯一的答案已被排除。 错误 ActionView::Template::Error (undefined method `new_record?’ for nil:NilClass): 1: 2: 3: 4: app/views/templates/_room_fields.html.erb:3:in `_app_views_templates__room_fields_html_erb__1867913568926009508_70125979350780′ app/views/templates/_form.html.erb:5:in `block (2 levels) in _app_views_templates__form_html_erb__4123974558704004784_70125994949300′ app/views/templates/_form.html.erb:4:in `block in _app_views_templates__form_html_erb__4123974558704004784_70125994949300′ app/views/templates/_form.html.erb:1:in `_app_views_templates__form_html_erb__4123974558704004784_70125994949300′ app/views/templates/new.html.erb:1:in `_app_views_templates_new_html_erb___3689493092838604682_70125964273280’Models 楷模 class Template true end class Room true end class Item < ActiveRecord::Base belongs_to :room end 表单视图 room […]

Rails 4 x Bootstrap 3 Datetimepicker:设计不好

我想在我的Rails4应用程序中应用Bootstrap3 Datetimepicker 。 但布局并不像这个页面那样好(在问题图像的中间)。 Rails 4 x Bootstrap 3 Datetimepicker:用datetimepicker替换默认的datetime_select 如果你能给我任何建议,我们将不胜感激。 _xxx_form.html.erb $(function () { $(‘#datetimepicker’).datetimepicker({format:’MMM-DD-YYYY’}); }); … 解决了!!! 将f.label移动到 之外后,布局如我所料。 … …

Rails 4 / postgresql index – 我应该使用一个datetime列作为索引filter,它可以有无限数量的值吗?

我需要优化查询以获取某个国家/地区的所有交易,然后才能在某个特定日期时间之前访问用户。 我的计划是实现以下索引 add_index(:deals,[:country_id,:last_user_access_datetime]) 我怀疑这个索引的相关性和有效性,因为列last_user_access_datetime可以具有日期的任何值ex:13/09/2015 3:06 pm并且它将经常更改(每次用户访问它时更新)。 如果我使用这个索引,这会使无限数量的值被索引? 我应该这样做还是避免使用’无限值的可能列,例如索引中的完全免费的datetime列?

Rails未知格式错误(HTML和JS)

我目前正在使用Rails 4,我有3个控制器执行以下操作: respond_to do |format| format.html format.js end 其中两个目前工作正常,但第三个控制器抱怨在ArticlesController#草稿中的ActionController :: UnknownFormat。 这是有问题的控制器: def drafts @user = current_user @drafts = @user.articles.paginate(page: params[:page], per_page: 5).draft_and_in_order respond_to do |format| format.html format.js end end 其他两个控制器包含格式片段的动作看起来相似。 它们都使用相同的ajax调用,所以它可能不是那样,并且调用只是对当前页面的简单默认ajax调用(例如) $.ajax({ }); 并且触发文章#rarafts action在我的rails服务器中看起来很好,因为它发出了正确的GET响应。 我认为可能是这种情况的唯一区别是文章#strafts在它之前有一个before_actions: before_action :logged_in_user, only: [:new, :create, :update, :destroy, :drafts] before_action :correct_user_format, only: [:new, :drafts] 因为它们包含一些redirect_to: def correct_user_format user = […]