Tag: ruby on rails

嵌套模型validation – 不显示错误

关于这一点有很多问题,但它们似乎都没有帮助。 是的,我看过这个导演 。 我有一个有很多书的作者,如下: 作者: class Author < ActiveRecord::Base attr_accessible :name has_many :books, dependent: :destroy accepts_nested_attributes_for :books, allow_destroy: true validates :name, presence: true validates :name, length: { minimum: 3 } end 书: class Book < ActiveRecord::Base attr_accessible :name, :year belongs_to :author validates :name, :year, presence: true validates :year, numericality: { only_integer: true, less_than_or_equal_to: Time.now.year } […]

Rails 3,如何在创建主记录后添加关联记录(Books,Auto Add BookCharacter)

Rails新手…试图了解正确的做事方式…… 在我的应用程序中,用户可以创建一本书(我有那个工作) 我想要发生的是当用户创建一本书时,一条记录被添加到BookCharacters表中,类似于(id,book.id,user.id,characterdescription.string。) 创建书籍后,创建它的用户应自动添加为第一个BookCharacter。 之后,用户可以根据需要手动添加/编辑任意数量的BookCharacters。 但最初我希望它们默认自动添加。 所以在我的Book控制器中,我有: def create @book = Book.new(params[:book]) respond_to do |format| if @book.save …. 使用Rails,是否可以在保存书籍后添加这种逻辑? 就像是 Book.create( :creator => current_user.id) 我很感激帮助

errors.full_messages:属性名称出现两次

这一直困扰着我。 我的所有模型都会出现此问题,但我会使用其中一个,测验,作为示例。 测验具有以下validation: validates_presence_of :size, :style 我正在使用I18n,并且我的翻译文件中有以下设置:(这些只是标准的错误消息,但我已将它们包含在我的en.yml中,以便很容易看到结构,如果我想要为任何特定型号覆盖它们) activerecord: errors: messages: inclusion: “{{attribute}} is not included in the list” invalid: “{{attribute}} is invalid” empty: “{{attribute}} can’t be empty” blank: “{{attribute}} can’t be blank” record_invalid: “Validation failed: {{errors}}” 问题是这样的:如果我做了一个新的测验,这将失败validation,然后查看quiz.errors.full_messages,每个错误消息都有属性然后是完整的消息: >> quiz = Quiz.create => >> quiz.errors.full_messages => [“Size Size can’t be blank”, “Style Style can’t be blank”] […]

部署后将自定义CSS和Javascript链接到Rails

我有一个Rails应用程序它的css和js链接在本地工作正常,因为我使用: 我用Google搜索了所有我发现的Heroku指南 ,我对资产管道事情感到困惑! 我也运行了这个命令: bundle exec rake assets:precompile 它确实在公共目录中创建了一些文件,如指南中所述: 现在在Heroku上一切都很简单,没有设计也没有Css和JS。 当我跑的时候 Heroku Logs 这就是我得到的CSS和JS文件的严重无路由匹配如下: 2013-06-10T10:06:28.184255 + 00:00 app [web.1]:ActionController :: RoutingError(没有路由匹配[GET]“/assetscv.png”): 这只是一行,我为其他文件获得了更多这些,并预先生成了loggs行 任何帮助将不胜感激谢谢! PS: 我试过了 我有一堆错误,在heroku上它说抱歉出了问题

在production.log中没有日志消息

我编写了一个演示HelloWorld Rails应用程序并使用WEBrick测试它(它甚至不使用数据库,它只是一个打印“hello world”的控制器)。 然后我尝试将其部署到使用Passenger的本地Apache。 事实上,这个测试只是让Passenger工作(这是我第一次在Apache上部署)。 现在我甚至不确定Passenger是否正常工作,但我在Apache方面没有任何错误。 当我http://rails.test/ ,浏览器显示Rails 500错误页面 – 所以我假设P​​assenger正常工作。 我想调查日志,但是生产.log是空的! 我不认为这是一个权限问题,因为如果我删除该文件,它会在我重新加载页面时重新创建。 我试图在conf/environments/production.rb更改日志级别,尝试使用Rails控制台生成手动写入日志文件 Rails.logger.error(‘asdf’) 它返回true但没有任何内容写入production.log。 路径(根据Rails.logger.inspect获得)是正确的,我注意到如果我手动删除它,该文件将被重新创建。 我怎么知道发生了什么? (我已经检查过Apache日志,另外我为Passenger设置了最高的调试级别,但它似乎是一个Rails问题,所以服务器没有记录)

生产中的字体问题envirnment rails

我制作了一个rails(4.2.4)应用程序,它在开发环境中运行良好,但是当我在数字海洋上部署它时,它没有得到字体,有一个像 Failed to load resource: the server responded with a status of 404 (Not Found) 跟路一样 http://Server-IP/assets/raleway-bold.woff2 我尝试了许多组合来提供路径,但除了一个之外都是徒劳的,它在开发中有效,但在生产中却没有。 我的资产结构差别不大 assets – fonts – javascripts – stylesheets – admin – web – application.js – fonts.cs – application.cs 并在fonts.cs我提供路径 @font-face { font-family: ‘dpdidot_htfm96medium’; src: url(‘/assets/dp_didot-htf-m96-medium-webfont.eot’); src: url(‘/assets/dp_didot-htf-m96-medium-webfont.eot?#iefix’) format(’embedded-opentype’), url(‘/assets/dp_didot-htf-m96-medium-webfont.woff2’) format(‘woff2’), url(‘/assets/dp_didot-htf-m96-medium-webfont.woff’) format(‘woff’), url(‘/assets/dp_didot-htf-m96-medium-webfont.ttf’) format(‘truetype’), url(‘/assets/dp_didot-htf-m96-medium-webfont.svg#dpdidot_htfm96medium’) format(‘svg’); font-weight: […]

has_many通过复选框

鉴于以下型号 class Feed :destroy has_many :users , :through => :alerts end class Alert < ActiveRecord::Base belongs_to :user belongs_to :feed has_and_belongs_to_many :alerttypes end class Alerttype < ActiveRecord::Base has_and_belongs_to_many :alerts end 我可以创建一个表单来列出添加新Feed时的Alerttypes并正确提交。 但是,我无法成功更新这些Alerttypes。 我似乎无法找到定义复选框命名的正确方法 检查“已检查”的Alerttypes有效,但编辑时这些Alerttypes中的任何更改都不会更新,并且它们将保持为首次创建时的状态。

如何在rails app中使用twitter bootstrap和bootstrap-sass?

我对此很新,但我无法弄清楚问题。 在twitter bootstrap中我会使用: Column1 Column2 一切正常。 但我不想直接将spanX和spanY写入我的html文件,而是想提供有意义的类名,例如: First Column Second Column 鉴于事实,我正在使用https://github.com/thomas-mcdonald/bootstrap-sass ,我该如何编写我的scss文件? 我尝试了以下,但它不起作用(不显示两列): @import “bootstrap”; @import “bootstrap-responsive”; .user-container { @extend .row-fluid; } .user-filter { @extend .span2; } .user-list { @extend .span10; } 如果我看一下生成的代码,在我看来一切都应该没问题: /* line 164, ../../../../../.rvm/gems/ruby-1.9.3-p125/gems/bootstrap-sass-2.0.0/vendor/assets/stylesheets/bootstrap/_mixins.scss */ .span2, .user-filter { width: 140px; } 等等。 我究竟做错了什么? 更新: 好吧,只是为了清楚是什么问题 – 列被列为行(一个接一个),而不是真正的列(彼此相邻),例如: with bootstrap:Column1 Column2 使用我的自定义类: […]

文件上传进度条与回形针上的回形针

我需要显示文件上传的进度条,我不知道。 任何帮助将不胜感激。 应用程序在Heroku上,文件在S3上

在尝试使用capistrano进行部署时,为什么会出现Psych错误?

我目前正在我的Rails 3.2.13应用程序中设置capistrano。 我收到以下错误/详细信息(包括“第1行第1列不允许使用控制字符”)。 我已经做了一些搜索,但没有看到任何与我有关的事情。 我正在使用rvm-capistrano和ruby 2.0.0-p195。 我最近将我的应用程序所需的环境变量移动到.bashrc中。 … * 2013-06-10 15:18:32 executing `deploy:assets:update_asset_mtimes’ * executing “[ -e /home/deployer/apps/super_rad_app/shared/assets/manifest* ] && cat /home/deployer/apps/super_rad_app/shared/assets/manifest* || echo” servers: [“107.20.249.163”] [107.20.249.163] executing command command finished in 6238ms *** [deploy:update_code] rolling back * executing “rm -rf /home/deployer/apps/super_rad_app/releases/20130610221258; true” servers: [“107.20.249.163”] [107.20.249.163] executing command ** [out :: 107.20.249.163] Using /home/deployer/.rvm/gems/ruby-2.0.0-p195 command […]