Tag: ruby on rails 4

如何在创建关联记录后正确创建关联记录?

我正在使用Ruby on Rails 4.1,我想知道它是否良好以及在创建关联器记录之后创建关联记录的缺点是什么 。 也就是说,例如,我有Article类和belongs_to article的Comment类,我想在创建文章后创建一个“默认”注释。 可能我可以使用回调方法来实现这一点,但还有其他方法可以实现我想要的吗? 我应该看什么是“平衡的”(例如:类/模块依赖)?

无法使用HMAC SHA256从示例中重现AWS签名

我正在关注这个例子 http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html 并试图重现64个字符串的签名,他们声称… aeeed9bbccd4d02ee5c0109b86d86835f995330da4c265957d157751f604d404 我已成功匹配Canonical Request的hex digeset,并确认StringToSign字符串是正确的。 最后一部分是计算signing_key和签名。 这是我使用提供的ruby函数’getSignatureKey’击中路障的地方 http://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html#signature-v4-examples-ruby signing_key = getSignatureKey secret_access_key, current_date, region, aws_service signature = OpenSSL::HMAC.digest(‘sha256’, signing_key, string_to_sign) def getSignatureKey key, dateStamp, regionName, serviceName kDate = OpenSSL::HMAC.digest(‘sha256’, “AWS4” + key, dateStamp) kRegion = OpenSSL::HMAC.digest(‘sha256’, kDate, regionName) kService = OpenSSL::HMAC.digest(‘sha256’, kRegion, serviceName) kSigning = OpenSSL::HMAC.digest(‘sha256′, kService, “aws4_request”) kSigning end ‘signature’的当前输出是这个奇怪的字符序列。 ٻ . […]

WicketPDF渲染表未正确对齐,页脚位于最后一页

我从html页面生成pdf报告,我分别用页眉和页脚创建了布局,我在最后一页只需要第一页和页脚的标题,我尝试了一些脚本但是它不起作用,以及如何避免分页在表格行内,我需要每个页面的边框,而不会破坏表格行,如图所示。 respond_to do |format| format.html format.pdf { render :pdf => “Report”, :template => ‘layouts/pdf_layout.pdf.erb’, :layout => ‘pdf_layout.pdf.erb’, :margin => {:bottom => 35}, :page_size => ‘A4’, :header => {:content => render_to_string({:template => ‘layouts/header.pdf.erb’})}, :footer => {:content => render_to_string({:template => ‘layouts/footer.pdf.erb’})} } end 任何其他建议 提前致谢

如何在rails中实现编辑/格式化文本区域

我想实现文本框(文本区域),如图所示。我知道简单的textarea但不知道这种类型的文本区域给出了格式化,编号设施,因为iam new to rails plz帮助我

在两个rails4应用程序之间共享会话

我正在用设计创建一个应用程序。 有两个域名1)www.test.com和2)www.hello.com两个域指向同一个应用程序。 所以我想在两个应用程序之间共享session(current_user)。 用户将登录(1)并且应该访问域(2)。 请建议什么是最好的方式。

Rails 4不加密cookie内容

你好我正在尝试加密和保护我的cookie中包含的数据,但似乎数据只被编码(base64) 这是一个例子: cookies.signed[:example] = { :value => ‘can you see this?’, :httponly => true, :expire_after => 30.minutes, :secure => true } 这是cookie的内容: BAhJIhZjYW4geW91IHNlZSB0aGlzPwY6BkVG–b4a8bbd7cd35e392ccd788df0008fd10b48442b2 如果我解码字符串(base64)我得到: I”can you see this?:EFom{q{vq{_M<}to8f 我想知道我错过了什么,目前这就是我所拥有的 session_store.rb: Service::Application.config.session_store :cookie_store, key: ‘_service_session’ 在我的secret_token.rb中我设置了这样的东西: Service::Application.config.secret_key_base = ‘e892d55cbc205bb6..’

如何让Active Admin在登录后与Pundit合作

我已将配置权威addapter授权添加到我的应用程序中 config.authorization_adapter = ActiveAdmin::PunditAdapter 当我使用admin@example.com凭据登录时,我收到此错误。 Pundit::NotDefinedError in Admin::Dashboard#index unable to find policy AdminUserPolicy Extracted source (around line #2): insert_tag active_admin_application.view_factory[“page”] 所以我在policies / active_admin文件夹中创建了这些文件 adminuser_policy.rb module ActiveAdmin class AdminUserPolicy < ApplicationPolicy class Scope < Struct.new(:user, :scope) def resolve scope end end def home? true end def index? true end def show? true end def new? true […]

活动模型禁止属性错误

有人能够帮助我理解这个错误。 我正在尝试按照构建Web应用程序教程在rails中创建联系表单。 我按照步骤生成了一个消息支架。 然后我修改了我的路线。 接下来它说把它放到消息控制器show动作中。 if @message.save flash[:notice] = ‘Thanks for Your Message’ format.html { redirect_to root_path } 我已经这样做了,我在MessagesController中得到以下错误ActiveModel :: ForbiddenAttributesError #create ActiveModel :: ForbiddenAttributesError 这是我的消息控制器文件 class MessagesController < InheritedResources::Base def show if @message.save flash[:notice] = 'Thanks for Your Message' format.html { redirect_to root_path } end end end 我的路线文件如下 # devise_for :users 资源:产品做资源:订单,只有:[:new,:create] #tells rails需要产品ID号码结束 […]

使用Rails 5在Heroku,PostgreSQL上运行迁移时出错

我使用PostgreSQL将Rails 5部署到Heroku中的免费应用程序。 这是我在database.yml配置: production: adapter: postgresql username: root password: database: example 当我运行heroku run rake db:migrate ,我看到这个错误: 耙子流产了! PG :: ConnectionBad:无法连接到服务器:没有这样的文件或目录服务器是否在本地运行并接受Unix域套接字“/var/run/postgresql/.s.PGSQL.5432”上的连接? 如果我将此行添加到database.yml : host: localhost 并再次运行迁移,我看到这个错误: 耙子流产了! PG :: ConnectionBad:无法连接到服务器:连接被拒绝服务器是否在主机“localhost”(127.0.0.1)上运行并接受端口5432上的TCP / IP连接? 怎么解决?

为什么尝试使用Grape with Rails失败了“未初始化的常量API”?

我希望有人解释为什么在Rails(4.1.8)和Grape(0.10.1)中发生这种情况 所以这是我的API: app/api/root.rb : module API class Root < Grape::API prefix 'api' mount API::V1::Root end end app/api/v1/root.rb : module API::V1 class Root < Grape::API version 'v1' mount API::V1::Users end end app/api/v1/users.rb : module API::V1 class Users < Grape::API format 'json' resource :users do desc "Return list of users" get '/' do User.all end end end […]