Questions tagged «ruby-on-rails»

Ruby on Rails是一个用Ruby编写的开源全栈Web应用程序框架。它遵循流行的MVC框架模型,并以其“配置之上的约定”方法进行应用程序开发而闻名。


4
Rails + New Relic:RPM是什么意思?
我刚刚开始在我的rails应用程序中使用New Relic RPM,它们提供的指标之一是“吞吐量RPM”。我到处搜寻Google并彻底梳理了New Relic文档,但找不到关于RPM吞吐量指标的任何书面说明。 是“每分钟的请求数”还是“每毫秒的请求数”或其他?* *内燃发动机和每分钟转数使之无法在Google中找到答案。 什么是吞吐量RPM?一个好数字是更高还是更低,一些平均基准是多少? 非常感谢您对此指标的解释,谢谢!

4
Rails 4:将属性插入参数
在Rails 3中,可以将属性插入到参数中,如下所示: params[:post][:user_id] = current_user.id 我正在尝试在Rails 4中做类似的事情,但是没有运气: post_params[:user_id] = current_user.id . . . . private def post_params params.require(:post).permit(:user_id) end Rails忽略了这种插入。它不会引发任何错误,只是会自动失败。

13
没有数据库的Rails模型
我想创建一个带有ActiveRecord验证的Rails(2.1和2.2)模型,但是没有数据库表。什么是最广泛使用的方法?我找到了一些声称可以提供此功能的插件,但是其中许多插件似乎并未得到广泛使用或维护。社区推荐我做什么?现在,我倾向于根据此博客文章提出自己的解决方案。

13
未检出...捆绑包安装不能解决帮助!
https://github.com/intridea/omniauth.git (at master) is not checked out. Please run `bundle install` (Bundler::GitError) 那我该怎么办?捆绑安装适用于开发,但是当我推送并部署到生产服务器时。即使在生产服务器上运行捆绑包安装后,我仍然收到此错误。
68 ruby-on-rails  ruby  git  gem 


17
nokogiri gem安装错误
我知道这个宝石有很多问题,但是没有答案对我有用。 当我在SSH中运行时,出现gem install nokogiri以下错误: Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0... OK Running patch with /home/user58952277/.gem/ruby/1.9.3/gems/nokogiri-1.6.2.1/ports/patches/libxml2/0001-Fix-parser-local-buffers-size-problems.patch... Running 'patch' for libxml2 2.8.0... ERROR, review 'tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0/patch.log' to see what happened. *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more …

2
从ActiveRecord范围中删除订单
我正在使用Rails ransack(https://github.com/ernie/ransack)来允许用户过滤和排序一些记录。我使用传统方法获得了经过过滤和排序的记录。 @invoices = Invoice.search(params[:q]).result 现在我想获得一些摘要信息,所以我有 @invoices = Invoice.search(params[:q]).result @summary = @invoices.select("sum(balance) as balance_total").first 用户指定要排序的字段时除外。我收到SQL错误: Column "project_name" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause 我可以从示波器中删除排序吗?怎么样? 谢谢

10
Rails:当数据库中没有元素时,一种优雅的消息显示方式
我意识到我正在写很多与此相似的代码: <% unless @messages.blank? %> <% @messages.each do |message| %> <%# code or partial to display the message %> <% end %> <% else %> You have no messages. <% end %> Ruby和/或Rails中是否有任何构造可以让我跳过第一个条件?这样当迭代器/循环甚至不会进入一次时将执行该操作?例如: <% @messages.each do |message| %> <%# code or partial to display the message %> <% and_if_it_was_blank %> …

4
如何使用Devise“软删除”用户
我目前在Rails项目中使用Devise进行用户注册/身份验证。当用户想要取消其帐户时,该用户对象被销毁,这使我的应用程序处于不希望的状态。 实现“软删除”的最简单方法是什么,即仅删除个人数据并将用户标记为已删除?我仍然想保留所有记录关联。 我认为我必须首先为用户介绍一个新的“已删除”列。但是随后,我在用户的个人资料视图中停留了以下默认代码: <p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p> 在哪里可以找到:delete方法?我应该如何覆盖默认的Devise方法?

6
“警告:无法批量分配受保护的属性”
我使用了RESTful技术来生成模型(实际上,我使用的是Devise gem,它为我完成了此工作),并且向模型添加了名为first_name和last_name的新字段。迁移进行得很好。我在模型中添加了attr_accessor:first_name,:last_name并期望它可以正常工作。但是,当我尝试使用Doctor.create({:first_name =>“ MyName”})等批量分配新实例时,出现错误,提示无法批量分配受保护的属性。 我认为使用attr_accessor的全部目的是避开模型字段的保护。您能帮助我理解此消息吗? 编辑:哦,顺便说一句,也不会创建记录。我认为应该这样做,因为这只是一个警告,但它们不在数据库中。 Edit2:这是我的模型 class Doctor < User has_many :patients has_many :prescriptions, :through=> :patients validates_presence_of :invitations, :on => :create, :message => "can't be blank" attr_accessor :invitations end 以及没有first_name和last_name的架构,因为它们是在users表中创建的,users表是医生的祖先。我使用了单表继承。 create_table :doctors do |t| t.integer :invitations t.timestamps end 这是更改用户表的迁移 add_column :users, :first_name, :string add_column :users, :last_name, :string add_column :users, …

8
从Rails 3表单提交中删除“ utf8 =✓”
我在Rails 3应用程序中有一个简单的搜索表单: <%= form_tag search_path, :method => "get" do %> <%= text_field_tag :q, params[:q] %> <%= submit_tag "search", :name => nil %> <% end %> 当用户单击“提交”按钮时,他们将进入URL:http%E2%9C%93 ://myapp.com/search?utf8=%E2%9C%93&q = foob​​ar (其中显示为复选标记:✓)。 我对该utf8参数不做任何事情,因此我想通过完全删除URL来保持URL干净。也就是说,我希望用户使用该URL:http://myapp.com/search?q = foob​​ar。 我该怎么做呢?

4
新+保存和创建之间的差异
我是Rails的新手,我不了解new + save方法和create方法之间的区别。 def create @item = Item.new(params[:item]) respond_to do |format| if @item.save format.html { redirect_to @item, notice: 'Item was successfully created.' } format.json { render json: @item, status: :created, location: @item } else format.html { render action: "new" } format.json { render json: @item.errors, status: :unprocessable_entity } end end …

6
Ruby JSON解析更改哈希键
可以说我有这个哈希: { :info => [ { :from => "Ryan Bates", :message => "sup bra", :time => "04:35 AM" } ] } 我可以通过这样做来调用信息数组hash[:info]。 现在,当我将其转换为JSON(JSON.generate),然后对其进行解析(JSON.parse)时,将得到以下哈希值: { "info" => [ { "from" => "Ryan Bates", "message" => "sup bra", "time" => "04:35 AM" } ] } 现在,如果使用hash[:info]它nil,它将返回,但是如果使用,则不会hash["info"]。 为什么是这样?而且是否有任何方法可以解决这种不兼容问题(除了从一开始就使用字符串键)?

3
如何将多个参数作为数组传递给ruby方法?
我在Rails助手文件中有这样的方法 def table_for(collection, *args) options = args.extract_options! ... end 我希望能够像这样调用此方法 args = [:name, :description, :start_date, :end_date] table_for(@things, args) 这样我就可以基于表单提交动态传递参数。我无法重写该方法,因为我在很多地方都使用了它,那么我还能怎么做呢?

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.