Tag: ruby on rails 3

如何根据Rails中的单个列计算记录与其他记录的排名?

假设我有一个名为point User模型。 如何将实例的排名与所有其他User行进行比较。

在应用程序中使用自动填充function进行搜索

美好的一天。 我讨厌使用ransack按照标题查找文章的控制器。 我需要用于查找信息以使用自动完成的字段。 目前它找到了,但没有自动完成,你可以帮我解决这个问题和gemhttps://github.com/crowdint/rails3-jquery-autocomplete-app ? 的Gemfile gem “ransack” gem ‘rails3-jquery-autocomplete’ gem ‘nifty-generators’ gem ‘jquery-rails’, ‘~> 2.0’ 在视图中: 15 %> ‘Search’, :class=>’fl_right’ %> 布局负责人: “all” %> 调节器 class ArticlesController < ApplicationController autocomplete :article, :title 更新1和routes.rb get ‘articles/autocomplete_article_title’ 在视图中更新2 ,代替<%= f.autocomplete_field :title_cont,使用1):title_start没有更改2):articles_article_title_start等导致错误。 更新3我编辑了routes.rb。 将’articles / autocomplete_article_title’移到了locale变量的范围内, 现在它有点工作了。 ..自动完成下拉列表出现…但是空:(现在必须修复那个。 更新4尝试使用http://railscasts.com/episodes/102-auto-complete-association 。 但它适用于较旧版本的rails ……等等 更新了routes.rb中的更新5 resources :articles do get […]

Gmaps4rails:当用户点击侧边栏中的链接时,如何更改标记的外观?

我正在尝试使用gmaps4rails获取此行为:用户单击侧边栏中的链接,地图上的相应标记更改图像/颜色,以使所选的一个与其他标记脱颖而出。 我试过这个代码 Gmaps.map.callback = function(){ var len = Gmaps.map.markers.length; for(var i = 0; i < len; i++){ marker = Gmaps.map.markers[i]; google.maps.event.addListener(marker.serviceObject, 'click', (function(i){ return function(){ console.log($(Gmaps.map.markers[i].serviceObject.ne.ga).attr("src", "/assets/marker_sprite2.png")); } })(i)); } } 但这会改变每个标记的外观,这对我正在尝试做的事情并不是很有用! 反正有没有实现这个目标? 编辑:使其工作,见下面的答案 编辑2:虽然这个解决方案适合我想要的,但我偶然发现了这个方法的另一个问题,请参阅下面的评论

ActionView :: MissingTemplate:缺少模板(尝试渲染不存在:移动格式)

我有一个index.js到位,可以从桌面启动,但当我尝试从Mobile Safari打开时出现以下错误。 ActionView::MissingTemplate: Missing template ads/thumbs/index, application/index with {:locale=>[:es, :en], :formats=>[:mobile], :handlers=>[:erb, :builder, :haml]}. Searched in: * “/app/app/views” * “/app/vendor/bundle/ruby/1.9.1/gems/devise-1.5.2/app/views” * “/app/app/views” 当文件夹中没有这样的文件时,我不确定它为什么要寻找:formats=>[:mobile] 。 尝试使用手机设备登录后也会发生同样的事情。 我尝试呈现一个不存在的create.mobile.haml文件。 PS 有没有办法制作:mobile视图到后备默认:html未找到:html视图? 那就是诀窍。

如何validation付款永远不会导致发票金额小于零?

我有这堂课: class Payment { :greater_than => 0, :less_than_or_equal_to => :maximum_amount } after_save :update_amount_payable after_destroy :update_amount_payable private def maximum_amount invoice.amount_payable end def update_amount_payable invoice.update_amount_payable end end class Invoice < ActiveRecord::Base has_many :payments after_save :update_amount_payable def update_amount_payable update_column(:amount_payable_in_cents, new_amount_payable) end private def new_amount_payable (total – payments.map(&:amount).sum) * 100 end end 上面的代码有效。 但是,如何确认没有付款金额可以导致invoice.amount_payable小于0 ? 特别是当同一张发票的多次付款可能时,这就变得棘手了。 我一直试图让我的头围绕这几个小时,但无济于事。 也许回滚数据库的回调可以在这里使用? 谢谢你的帮助。

rails 3.2的未定义方法 _index_path

好的,这继续让我感到困惑: 1)这是在我的控制器(personalias_controller.rb) def new @personalia = Personalia.new end 2)我有一个名为personalia.rb的模型 3)我有 resources :personalias 在routes.rb中 当我尝试渲染个性化forms时,我仍然得到未定义的方法`personalia_index_path’(来自views / personalias / new.html.erb: 这让我疯狂: – |

仅当virt_attribute为false时才validation字段

我有这样的模特: class Order {:message => I18n.t(:city_not_chosen)} validates :zip, :presence => {:message => I18n.t(:zip_not_chosen)} validates :street, :presence => {:message => I18n.t(:street__not_chosen)} validates :building, :presence => {:message => I18n.t(:building_not_chosen)} validates :phone_number, :presence => {:message => I18n.t(:phone_number_not_chosen)} validates :receiver, :presence => {:message => I18n.t(:receiver_not_chosen)} end 正如你所看到的,我在模型中设置了一些非db字段(use_user_data) – 虚拟属性… 但是怎么做,如果:use_user_data是假的,好的和正确的validation,但是当真的没有validation? 我试试这样: validates :city, :presence => {:message => I18n.t(:city_not_chosen)}, :unless […]

预编译资产失败

我正在推动一个我几个月没有更新的应用程序,我遇到了这个问题。 我只在代码中更改了一些变量。 不知道为什么突然这样对我。 ! ! Precompiling assets failed. ! ! Push rejected, failed to compile Ruby app To git@heroku.com:myapp.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to ‘git@heroku.com:myapp.git’ rake aborted! could not connect to server: Connection refused Is the server running on host “127.0.0.1” and accepting TCP/IP […]

NoMethodError的完整跟踪

这基本上是我之前问题的第2部分,因为我已经根据代码的长度创建了一个新问题。 希望我们能够在您的帮助下解决这个问题,我相信我们现在可以通过新信息找到解决方案。 编辑:感谢您的输入。 这是pt的链接。 1与实际代码: 登录function不起作用 。 PS。 请不要忘记投票这个问题。 inheritance人user.rb: # == Schema Information # # Table name: users # # id :integer not null, primary key # name :string(255) # email :string(255) # created_at :datetime not null # updated_at :datetime not null # encrypted_password :string(255) # salt :string(255) # class User true, :length => […]

输入url时出现新的rails安装错误

已解决在/etc/apache2/vhosts.d/default.conf中,我们插入了以下内容 RewriteEngine On RewriteRule “^/?$” “http://ourpage.com/projects” ————————————————– ————————————————– ———- 我们在新服务器上安装了rails。 当我们尝试访问url我们会被重定向到ourstuff/public ,这是ourstuff/public 。 在我们的app, config, public有app, config, public等。 编辑:可能是mod乘客不能正常工作吗? 浏览器中显示以下内容(参见scrshot)。 我的同事从apache配置文件的纪录片根据说。 上市 当我们从其他系统中尝试通常的url xyz.com/ourstuff ,我们会收到此错误 路由错误 No route matches [GET] “/ourstuff” Try running rake routes for more information on available routes. 有谁知道为什么会这样? 谢谢你的支持。