Tag: ruby on rails 3.2

升级到rails 3.2.1后如何处理供应商/插件

升级到rails3.2.1后,会出现此警告: 你在供应商/插件中有Rails 2.3风格的插件! 在Rails 4.0中将删除对这些插件的支持。 将它们移出并将它们捆绑在Gemfile中,或者将它们作为lib / myplugin / *和config / initializers / myplugin.rb折叠到您的应用程序中。 有关详细信息,请参阅发行说明: http : //weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released 我在plug / plugins目录中移动我的插件,但我不知道如何编写config / initializers / myplugin.rb文件,谷歌找不到答案。

Bundler找不到gem“activesupport”的兼容版本

我迁移到3.2.13版本的rails并且我收到此错误,我该如何摆脱这个? Fetching gem metadata from https://rubygems.org/……. Fetching gem metadata from https://rubygems.org/.. Resolving dependencies… Bundler could not find compatible versions for gem “activesupport”: In snapshot (Gemfile.lock): activesupport (3.2.12) In Gemfile: rails (= 3.2.13) ruby depends on activesupport (= 3.2.13) ruby Running `bundle update` will rebuild your snapshot from scratch, using only the gems in your Gemfile, […]

Rails ActiveRecord关系助手如何允许诸如`user.groups.new`之类的方法?

在Rails中,我创建了一个模型,用于从LDAP数据库而不是ActiveRecord中检索用户。 现在我尝试将我的ActiveRecord模型与基于LDAP的模型集成,因此我在模型中编写模拟一些常见ActiveRecord方法的方法。 我试图模仿的方法之一是通常由ActiveRecord上的has_many通过关系创建的方法。 在ActiveRecord中,此关系将允许以下内容: user = User.first groups = user.groups # == Array of Groups groups << Group.create(name: "Test") # How does Rails allow this? Rails究竟是如何允许的? 我已经尝试动态地将方法分配给user.groups返回的数组实例,但似乎没有任何方法可以让这些方法知道数组是从哪个用户记录创建的。 (因此他们可以在新的关系记录上分配user_id 。)我缺少什么?

在rails中如何限制用户在要求升级其帐户之前保存在数据库中的post数

我正在添加一种控制非订阅用户和订阅用户的小方法。 基本上我的想法是所有使用Devise注册的用户都可以获得一个帐户。 但是,根据找到的用户ID,我的模型或用户在数据库中可以拥有的post数量应为25个post。 我猜这些会起作用; 模型 class Post belongs_to :user validate :quota, :on => :refresh def quota Posts = Posts.find(params[:id]) if user.posts.count >= 25 flash[:error] = “Sorry you need to upgrade” end end end :refresh是我正在努力抓取post的地方,并将这些post添加到数据库中的current_user,或者将current_user id分配给它添加到数据库的每个post。 我对上述function是否正确? 或者我应该将validation计数添加到我的刷新控制器/模型中,如此; class dashboard def refresh … if self.user.posts.count >= 25 flash[:error] = “You’ve reached maximum posts you can import” […]

如何使用Devise锁定用户?

我想在我的应用程序中为帐户持有者用户添加订阅类型function,以便在固定的时间间隔后他们将无法访问其帐户? 注意:我不想从数据库中删除他们的帐户。 我已经在我的应用程序中安装了devise-2.1.2 。 有没有人知道怎么办? 我是Ruby on rails新手,所以如果你能解释一下这对我很有帮助。

REXML :: Document.new我们可以在这行上给出编码参数吗?

doc = REXML :: Document.new file只要我的xml文件包含UTF-8以外的一些特殊字符,我的代码就会失败。 REXML::ParseException (#<REXML::ParseException: #

如何将javascript对象的javascript值传递给ruby on rails中的控制器?

我有一个任务要在轨道上使用ruby做knockout.js。 我想将javascript值发送给控制器。 我的index.html.erb是 Country State Remove Add Submit $(document).ready(function() { function formatCurrency(value) { return “$” + value.toFixed(2); } var CartLine = function() { var self = this; self.category = ko.observable(); self.product = ko.observable(); self.subtotal = ko.computed(function() { return self.product() ? self.product().price * parseInt(“0” + self.quantity(), 10) : 0; }); // Whenever the category changes, reset […]

未定义的方法`email’代表nil:Exibe中的NilClass父表的邮件

我有一个问题,我做这个atribbuition我评论模型: class Comment < ActiveRecord::Base attr_accessible :comment belongs_to :post belongs_to :user 这在用户模型中 class User < ActiveRecord::Base attr_accessible :email, :password, :password_confirmation has_many :posts has_many :comments 但这不起作用: 出现错误: undefined method `email’ for nil:NilClass 请问有什么问题,在评论的创建中我做了atribbuition,看看: @comment = @post.comments.create(params[:comment],:user_id => current_user.id) 我如何解决这个错误,请 – 更新下一个响应,错误持续: 我试试这个: @comment = Comment.new(params[:comment]) @comment.user = current_user @comment.post = @post @comment.save 这个 @comment = @post.comments.create(params[:comment].merge(:user_id […]

Sass :: SyntaxError未定义变量

我是Asset Pipeline的新手,所以如果我做错了,请告诉我。 使用Rails 3.2和SASS。 我有一个配置部分定义了一堆我想在整个scss文件中使用的SASS变量。 根据本指南 ,我首先导入configuration ,然后是bonus 。 但是,我继续在bonus.css.scss中得到一个Sass::SyntaxError表示Undefined variable: “$darkRed” 。 我究竟做错了什么? application.css.scss /* * This is a manifest file that’ll be compiled into application.css, which will include all the files * listed below. * * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, * or vendor/assets/stylesheets of plugins, if any, […]

带复选框的Rails HABTM

我有三个表,帐户,广告系列和accounts_campaigns。 我希望在广告系列修改表单中为选定帐户设置复选框。 我有这样的Campaign模型: class Campaign < ActiveRecord::Base has_and_belongs_to_many :accounts accepts_nested_attributes_for :accounts end 我想我不需要在Account上定义关系。 我的表格是: = hidden_field_tag “campaign[accounts_ids][]”, nil – Account.all.each do |account| %label.checkbox = check_box_tag “campaign[accounts_ids][]”, account.id, @campaign.account_ids.include?(account.id), id: dom_id(account) = “#{account.name} – #{account.email}” 但是我收到了这个错误: unknown attribute: accounts_ids