Tag: 的Ruby on 轨道

在轨道上制作ruby会占用更少的内存

我正在尝试在VPS上运行Ruby on Rails项目( redmine )。 它工作正常,但需要相当多的RAM。 与其他VPS相比,rails应用程序的使用率非常低。 我也在服务器上运行lighttpd。 我是Ruby的新手,并且知道有几种方法可以在Ruby中启动webapp。 我目前正在使用webrick(并且可以手动启动它)。 是否有另一种方法来启动更高效的内存?

如何在调用render_to_string呈现模板时使Rails辅助方法可用

我有一个ActiveMailer类,在里面我使用render_to_string方法发送附带PDF模板的电子邮件,如下所示: def send_sales_order(email_service) @email_service = email_service @sales_order = SalesOrder.find_by_cid(email_service.order[:id]) mail(:subject => I18n.t(“custom_mailer.sales_order.subject”, company_name: “test”), :to => @email_service.recipients) do |format| format.html format.pdf do attachments[‘purchase_order.pdf’] = WickedPdf.new.pdf_from_string( render_to_string(‘sales_orders/show.pdf.erb’, locals: {current_company: @sales_order.company}) ) end end end 在show.pdf.erb模板中,我调用了我在其他地方定义的辅助方法,例如在ApplicationController中定义的current_company方法,如下所示: class ApplicationController < ActionController::Base helper_method :current_company, :current_role def current_company return if current_user.nil? if session[:current_company_id].blank? session[:current_company_id] = current_user.companies.first.id.to_s end @current_company ||= Company.find(session[:current_company_id]) […]

Ruby on Rails和来自PSP的奇怪的HTTP_ACCEPT标头

我有Ruby on Rails应用程序(3.1rc4),我每天都会使用相同的用户代理(Mozilla / 4.0(PSP(PlayStation Portable); 2.00))获得一些例外。 例外: A ActionView::MissingTemplate occurred in home#index: Missing template home/index, application/index with {:formats=>[“*/*;q=0.01”], :locale=>[:en, :en], :handlers=>[:erb, :builder, :arb]}. Searched in: “/var/www/releases/20110721144523/app/views” 我有app / views / home / index.html.erb,但看起来它试图找到一个非常奇怪的请求格式“ / ; q = 0.01”的文件。 HTTP标头: * HTTP_ACCEPT : */*;q=0.01 任何人都可以帮我解决这个问题?

重定向或渲染后不显示Flash消息

使用导轨4和ruby2 无法显示来自控制器的Flash消息。 我的方法看起来像这样: def create @salary_report = SalaryReport.create(salary_report_params) if @salary_report.save redirect_to @salary_report flash[:notice] = “Lönerapporten sparades korrekt!” puts “salary report saved #{flash[:notice]}” else render :new, notice: “Något gick fel när lönerapporten skulle sparas!” end end 正如您所看到的,我添加了一个puts语句,打印出flash通知只是为了certificate重定向后生成了闪存通知。 创建薪水报告后,日志如下所示: Redirected to http://localhost:3000/salary_reports/20 salary report saved Lönerapporten sparades korrekt! Completed 302 Found in 25ms (ActiveRecord: 9.7ms) 在显示查看日志后: Started […]

Rails:成分的未定义方法`map’

尝试入门的完整铁轨新手。 我有两个课程,即成分和单元。 有三个单位,磅,加仑和几十个,每个成分只有一个单位。 我想我已经正确设置了关联/路由。 在创建新配料时,我需要用户从这三个设置单位。 我用另一个问题来解决这个问题: Drop Down Box – 填充表格中另一个表的数据 – Ruby on Rails 成分模型: class Ingredient < ActiveRecord::Base belongs_to :unit end 单位模型: class Unit < ActiveRecord::Base end 路线: map.resources :ingredients, :has_many => :unit_conversions map.resources :units, :has_many => :ingredients 配料新控制器 def new @ingredient = Ingredient.new respond_to do |format| format.html # new.html.erb format.xml { render […]

新的elasticsearch-rubygem与铁轨融为一体

有什么方法可以将新的Elasticsearchgem用于ruby到轨道,轮胎很棒但是从两个月开始退役并且被新gem取代,但是,还没有与轨道集成function。 所有教程都使用轮胎,但现在,我们如何使用Elasticsearch的rails?

如何自定义Mailboxer电子邮件的模板?

它自动发送电子邮件说 You have a new message: subject You have received a new message: Body Visit http://example.com/ and go to your inbox for more info 任何人都知道如何自定义此模板? 如果可能,我想使用i18n作为此模板表单。 谢谢!! 。

自动重新加载导轨模块

我正在开发一个我在rails应用程序中包含的ruby模块。 我希望它在更改时自动重新加载。 我已经做了大量的谷歌搜索,并查看了讨论它的各种问题,但它们似乎都过时或者错了。 如何更改外部模块在rails中重新加载? 我已经尝试将其名称添加到ActiveSupport::Dependencies.unloadable_constants ,但是在我输入reload! 在控制台中,我不能再引用没有NameError: uninitialized constant foo符号NameError: uninitialized constant foo ,即使我做另一个require ‘foo_module’ 。 有谁知道如何使这个工作? 注意:这里有一个可能的dup ,但在“回答”的注释中注意它从未解决模块的问题。 还有这个问题在答案中有一个死链接,最后这个问题也没有解决。

处理控制器操作为JS而不是HTML

所以我有以下forms: ‘profile’, :action => ‘follow_topic’), :remote => true do %> ‘link’, :onclick => “javascript:document.getElementById(‘followtopic#{Topic.find(topic_id).identifier}’).innerHTML=’Following…'” do %> Follow 我试图让控制器将其作为JS代替HTML来处理它。 有趣的是我在应用程序中的另一个地方有一个完全像这样的表单似乎工作正常,并且控制器定义是相同的。 无法弄清楚问题所在。 关于我应该先检查什么的任何想法? def follow_topic @topic = Topic.find(params[:topic_id]) current_user.follows << @topic respond_to do |format| format.js end end

我可以在database.yml中指定rails环境应该只读访问数据库吗?

我们的应用程序具有非常标准的数据库配置。 在实时服务器上,如果我想查询数据库的内容,我必须运行script/console production或script/dbconsole production ,我冒险意外修改我们的数据。 我想创建一个新的rails环境,只读访问同一个数据库,这样我就可以在没有风险的情况下以script/console readonly方式运行script/console readonly或者script/dbconsole readonly 。 我见过的解决方案涉及添加一个新的mysql用户,或猴子修补ActiveRecord :: Base。 我不想这样做 – 我想在database.yml中指定与数据库的连接应该只读。 这是可能的,如果是的话,我该怎么做? 我尝试过添加readonly: true但它被忽略了。