Tag: ruby on rails 4

Rails 4相当于Rails 3’Mode.all’

在Rails 3中,如果我想点击db,我会在查询结束时使用.all。 这对于我在写入时刷新缓存(因此读取总是命中缓存)这一点非常有用。 现在在Rails 4中,Model.all返回一个ActiveRecord::Relation对象(即没有命中db)。 让它真正进入数据库并返回指定记录的最佳方法是什么?

设计Flash方法导轨

我正在使用Rails 4,Twitter Bootstrap 3.0和Devise 3.0。 我正在尝试为设计和我的网站的其余部分获得完全相同的flash消息。 到目前为止我有这个: 在“app / views / layouts / application.html.erb”中 : “app / views / layouts / _messages.html.erb” : <div class="alert alert-“> × 我创建了一个“app / helpers / devise_helper.rb”来覆盖默认的设计错误消息: module DeviseHelper def devise_error_messages! end end “app / helpers / application_helper.rb” : def devise_flash if controller.devise_controller? && resource.errors.any? flash.now[:error] = flash[:error].to_a.concat resource.errors.full_messages flash.now[:error].uniq! […]

Ruby on Rails中的Bootstrap工具提示

我现在试着把这件事做了很长一段时间,我无法弄清楚什么是错的: 我的链接: {:toggle=>”tooltip”}, ‘data-original-title’ => “Hey Whats up”, ‘data-placement’ => ‘right’%> 我的Javascript: $(‘.tag-tooltip’).tooltip(); 但它不起作用……我缺少什么? 编辑 如果我进入我的Chrome控制台并插入( $(’。tag-tooltip’)。tooltip(); )它正在运行。 所以我猜js文件没有加载? (我检查了我的application.js,我要求一切。)

Rails资产没有预编译,css在生产中看起来不同

在开发模式下我的rails应用程序工作和看起来完全符合我的要求,但在生产中它在chrome和safari上看起来不同,在safari中徽标图像加载但不是字体,在chrome中加载字体而不是图像加上输入字段有点长,并且在chrome中不对齐,但在开发模式下,它们在chrome中看起来都很棒 我一直搞乱了这一点,并删除了公共/资产几次 rake assets:precompile RAILS_ENV=production 没有成功,预编译没有错误 配置/ application.rb中: # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # — all .rb files in that directory are automatically loaded. config.assets.paths << "#{Rails.root}/assets/fonts" config.assets.paths << "#{Rails.root}/assets/images" config.assets.paths << Rails.root.join("app", "assets", "fonts") config.assets.precompile += %w( .svg .eot .woff […]

导轨4中未允许的参数

我读到了关于collection_check_boxes但我不明白如何设置选中的值。 我有以下型号: class Objective < ActiveRecord::Base has_many :indicators has_many :objective_children, class_name: "Objective", foreign_key: "parent_id" def objective_ids objective_children.collect{|o| o.id} end def objective_ids= objectives_ids objectives_ids.each do |id| objective_children << Objective.find(id) end end end 编辑视图: html复选框没问题,但我不知道如何将值设置为objective 。 我试过定义objective_ids= objectives_ids但没有任何反应。 在控制器中: class ObjectivesController < ApplicationController def objective_params params.require(:objective).permit(:name, :code, :description, :objective_ids) end end 编辑日志文件显示未Unpermitted parameters: perspective_id, objective_ids

公共活动上的未定义方法`destroy’

用户可以在屏幕上发表评论,并由PublicActivity跟踪: @comment.create_activity :create, owner: current_user, recipient: @comment.screen.user 并且评论依赖于::在屏幕模型上销毁。 但是当我删除屏幕时,删除评论时,该评论的PublicActivity记录仍然存在。 这是我的Screens Controller : def destroy @activity = PublicActivity::Activity.find_by_trackable_id(params[:id]) @activity.destroy #<– Heres the Problem @screen.destroy respond_to do |format| format.html { redirect_to root_path } format.json { head :no_content } end end 但是在删除屏幕时,我得到了undefined method destroy’for nil:NilClass`。 我在Railscast上读到: 它是由于在对象被销毁后调用create_activity方法。 根据gem维护者的说法,你只需假设记录将被销毁,并在销毁之前调用create_activity 我错过了什么? 以下信息 screen.rb belongs_to :user has_many :comments, :dependent => :destroy […]

PG :: ConnectionBad FATAL:角色“Myname”不存在

我正在尝试使用PostgreSQL,以便我可以部署到Heroku。 但是我不能再运行localhost了么? 我收到以下消息: PG::ConnectionBad FATAL: role “Myname” does not exist 这是我的databse.yml development: adapter: postgresql database: my_database_development pool: 5 timeout: 5000 test: adapter: postgresql database: my_database_test pool: 5 timeout: 5000 production: adapter: postgresql database: my_database_production pool: 5 timeout: 5000 这是我的gemfile: source ‘https://rubygems.org’ # Bundle edge Rails instead: gem ‘rails’, github: ‘rails/rails’ gem ‘rails’, ‘4.0.3’ # Use […]

获得:“迁移正在等待; 运行’bin / rake db:migrate RAILS_ENV = development’来解决此问题。“克隆并迁移项目后

我克隆了我的项目。 捆绑“捆绑安装”,然后运行“rake db:migrate”。 我收到此错误:(当我运行rails服务器并将我的浏览器打开到localhost:3000时)“迁移正在等待;运行’bin / rake db:migrate RAILS_ENV = development’以解决此问题。” 我逐个检查了所有迁移,并且所有迁移都没有错误地执行。 执行“rake db:migrate”后也没有显示错误。 这是我执行“ rake db:migrate:status ”时看到的内容 我在开发环境。 如果您需要任何其他信息,请告诉我。 我还尝试了“捆绑exec rake db:migrate”,并将“捆绑exec rake db:migrate:reset”改为“burninggramma”建议。 什么导致错误的线索?

在Rails 4上禁用Sprockets资产缓存

另一个问题“ 在开发中禁用Sprockets资产缓存 ”解决了如何在Rails 3.2中禁用Sprockets缓存。 你如何在Rails 4上做同样的事情? 我正在开发一个资产管道深处的gem,并且必须清除tmp/cache/*并重新启动Rails会变得很累。

Redis引发错误:NOAUTH需要身份validation,但没有密码设置

当我通过命令连接到Redis服务器时,我收到错误NOAUTH身份validation : redis-cli并运行ping以检查Redis是否正常工作。 我找到NOAUTH身份validation所需的错误答案 ,该错误描述了此错误仅在Redis设置密码时发生,但我在etc/redis/redis.conf检查了Redis配置文件,并且没有密码设置。 有没有人知道,如果有其他设置可以导致此错误? 谢谢你的帮助。 p / s:我使用的是Ruby on Rails Web框架,Redis数据库用于Sidekiq。 编辑:Redis版本是2.8.4。 服务器托管在AWS上。 目前,我决定为Redis服务器设置一个密码,以便在运行时无法设置密码。 (重启Redis服务器时,它将正常工作。您可以运行sudo service redis-server restart来重启Redis服务器。)