我有一个仅限 Rails 5 API 的应用程序,想要在 JSON 请求的响应中发送 cookie。当我使用 ActionDispatch::Cookies 在请求的响应中设置 cookie 时,它不会Set-Cookie在响应中设置标头。虽然response.set_cookie确实有效。
我还在应用程序控制器中进行了钩子测试after_action,我看到Set-Cookieheader 不存在于 response.headers 中,但存在 cookies['name_of_cookie'] 。我还想问的一个问题是这些 cookie(ActionDispatch::Cookies) 何时设置响应头?它发生在机架中吗?
withCredentialsAccess-Control-Allow-Credentials: true和Access-Control-Allow-Origin: <origin (request.headers['origin'])>存在config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Session::CookieStore, key: '_namespace_key'
Run Code Online (Sandbox Code Playgroud)
afterRails 应用程序中的任何回调挂钩中,还是发生在机架中?因为直到after_action在 applicaton_controller 中标题才不存在。domaincookie的设置有关系?我还在生产中使用 secure 和 httponly cookie,但在开发中仅使用 httponly。 …我正在运行带有rails exception-notifier gem的rails3.当发生异常,并且应该发送电子邮件时,我从ParameterFilter类中获得异常.我在rails源中发现了这个问题,我不确定最好的方法.
问题发生在ActionDispatch :: Http :: ParameterFilter中.在compiled_filter方法中,第38行发生错误:key = key.dupwhen key是符号,因为符号不可复制.这是来源:
def compiled_filter
...
elsif blocks.present?
key = key.dup
value = value.dup if value.duplicable?
blocks.each { |b| b.call(key, value) }
end
Run Code Online (Sandbox Code Playgroud)
我看到他们只是在它dup出现value时才会打电话duplicable.如果我修补源只调用dup的key时候key是duplicable,那么我的问题消失.我假设有一个理由为什么作者提出了这个条件value而不是key,所以我很好奇是否有人对这个代码有更好的理解.
只有在application.rb中向过滤器参数添加块时才会出现此错误.所以,也许我的原始问题有一个解决方法,不需要在这里使用块.如果您有兴趣,请参阅我的同事的问题Rails:从日志中过滤JSON参数中的敏感数据
这是一个问题的关键是:action.这来自rails,我不知道是否有办法强迫它成为一个字符串.
我提交了一个rails bug https://rails.lighthouseapp.com/projects/8994/tickets/6557-symbol-duplication-error-in-parameterfilter-compiled_filter我有一个准备好的补丁,如果key.duplicable?到key.dup线,我是寻找关于这是否是正确解决方案的输入.
将应用程序从 Rails 4.2.9 迁移到 5.2.1。
这是最新一期:
$ rails console
/Users/meltemi/rails/myapp/config/initializers/disable_xml_params.rb:3:in `<top (required)>': uninitialized constant ActionDispatch::ParamsParser (NameError)
from /Users/meltemi/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/engine.rb:657:in `block in load_config_initializer'
from /Users/meltemi/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/notifications.rb:170:in `instrument'
from /Users/meltemi/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/engine.rb:656:in `load_config_initializer'
Run Code Online (Sandbox Code Playgroud)
初始化程序中有问题的代码行:
# config/initializers/disable_xml_params.rb
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::XML)
Run Code Online (Sandbox Code Playgroud)
Rails 指南说:
ActionDispatch::ParamsParser 已弃用并已从中间件堆栈中删除。要配置参数解析器,请使用 ActionDispatch::Request.parameter_parsers=。(提交,提交)
所以我尝试了以下方法:
ActionDispatch::Request.parameter_parsers.delete(Mime::XML)
Run Code Online (Sandbox Code Playgroud)
但这会产生更多错误:
$ rails console
/Users/meltemi/rails/myapp/config/initializers/disable_xml_params.rb:3:in `<top (required)>': uninitialized constant Mime::XML (NameError)
from /Users/meltemi/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/engine.rb:657:in `block in load_config_initializer'
from /Users/meltemi/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/notifications.rb:170:in `instrument'
from /Users/meltemi/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/engine.rb:656:in `load_config_initializer'
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来调用该对象的 .delete ?
这是我第一次在这里提问,希望我能很好地解释我的问题。在我最近的一项任务中,我将应用程序升级到 Ruby 和 Rails(Ruby 2.6.6 > 2.7.2、Rails 6.0.3.2. > 6.1.1)。在此过程中我遇到了几个问题,升级了一些 gems 和 JS图书馆。该应用程序在模式下运行良好development。但是,当我切换到production模式时,我运行这些命令来编译和运行服务器。
RAILS_ENV=production bundle exec rake webpacker:compile
./node_modules/webpack/bin/webpack.js --config webpack.config.js
Run Code Online (Sandbox Code Playgroud)
当我运行该应用程序时,在production模式下它看起来运行正常,但是当我进入localhost:3000它时,它会抛出几个500与 CSS 文件有关的错误。我看到应用程序的主页是纯 HTML,没有 CSS。
2021-01-22 11:50:51 -0500 Rack app ("GET /assets/stylesheets/app-styles-3661efb317da3fb28f52.css" - (127.0.0.1)): #<NoMethodError: undefined method `match?' for #<ActionDispatch::FileHandler:0x00007ff610502c20>>
2021-01-22 11:50:25 -0500 Rack app ("GET /assets/landing.debug-05588bd014e46c264aaf6e00d2f5c570dd7ca3ed42336c2ff6d5c05bf986afe2.js" - (127.0.0.1)): #<NoMethodError: undefined method `match?' for #<ActionDispatch::FileHandler:0x00007ff610502c20>>
2021-01-22 11:50:25 -0500 Rack app ("GET /assets/companyLogo-6700adf796812269b9428251803c253b9c073095ef511d3619d269a0fdd96435.png" - (127.0.0.1)): #<NoMethodError: undefined method `match?' for …Run Code Online (Sandbox Code Playgroud) 我有一个支持多个域的rails应用程序,每个域可能有多个子域.
访问mydomain1.com的用户不会获得与mydomain2.com相同的体验(尽管应用程序的基本行为相同)
因此,如果用户登录到mydomain1.com,则不应该登录到mydomain2.com
如果用户在给france.mydomain1.com登录,就应该再进行中germany.mydomain1.com登录
以前,我通过在会话存储配置中设置域来处理此问题:
MyApp::Application.config.session_store :cookie_store, :key => '_MyApp_session', :domain => APP_CONFIG[:domain]
Run Code Online (Sandbox Code Playgroud)
我正在尝试找出处理多个域的最佳方法吗?
我已经尝试过黑客攻击,ActionDispatch::Callback但是请求无法从那里获得.
任何人都可以建议在一个应用程序中支持多个cookie的好方法吗?
理想情况下,我想为每个子域创建一个新的cookie .
cookies ruby-on-rails session-cookies actiondispatch ruby-on-rails-3
你如何使用ActionDispatch :: Routing :: RouteSet recogn_path?
我想获取视图的当前路径.
我试过<div id="<%= ActionDispatch::Routing::RouteSet::recognize_path %>">但是为ActionDispatch :: Routing :: RouteSet:Class得到了"未定义的方法`recogn_path'".
谢谢!
rack-timeout包含在Gemfile中,但我们只希望它作为生产中的中间件.因此,在初始化程序中,我们有:
config.middleware.delete Rack::Timeout
Run Code Online (Sandbox Code Playgroud)
检查此行之前和之后显示从阵列中删除了机架超时.无论如何,请求仍然超时,宝石中的快速"放置"表明它确实是罪魁祸首.
这是因为在调用delete之前已经构建了中间件堆栈吗?或者在每个请求中读取堆栈?如果是这样的话,可能是什么问题?
我看到两个不同的值request.env['CONTENT_TYPE']和request.content_type.
从单独的应用程序,我发送请求到我的Rails应用程序并明确设置Content-Type为text/xml.
以下是我在Rails应用程序中看到的另一端:
request.env['CONTENT_TYPE'] = "text/xml"
request.content_type = "application/xml"
Run Code Online (Sandbox Code Playgroud)
request.content_type 实际上是 action_dispatch.request.content_type
request.env['CONTENT_TYPE']和之间有什么区别request.content_type?content-type ruby-on-rails httprequest actiondispatch ruby-on-rails-3
我正在使用Ruby on Rails 3.1(RC1)创建一个Web应用程序.我正在使用Factory Girl,RSpec和Cucumber(与Capybara)进行测试,但是ActionDispatch::ClosedError当我创建新用户时(通过User模型的创建操作),我在某些时候(不是每次)遇到意外的提升.以下是我收到的错误消息:
Cannot modify cookies because it was closed. This means it was already streamed
back to the client or converted to HTTP headers. (ActionDispatch::ClosedError)
Run Code Online (Sandbox Code Playgroud)
使用这些创建用户的方法时会引发错误:
Factory.create( :user )Factory.build( :user ).saveUser.create( { ... } )User.new( { ... } ).save有趣的是,他们在一些测试中工作,但在其他测试中没有,并且它看起来并不随机,尽管我无法弄清楚原因.以下是我的代码的摘录:
需要'spec_helper'
def user
@user ||= Factory.create( :user )
end
def valid_attributes
Factory.attributes_for :user
end
describe UsersController do
describe …Run Code Online (Sandbox Code Playgroud) cucumber rspec2 actiondispatch ruby-on-rails-3.1 factory-bot
我看到我可以在这里过滤来自Rails日志的密钥,但我不能完全清楚如何过滤嵌套在参数哈希中的密钥.
我的params哈希看起来像这样:
{"download"=>{"attachment_id"=>"54039", "data"=>"data:image/png;base64,iVBORw0..."}}
Run Code Online (Sandbox Code Playgroud)
params[:download][:data]base64字符串在哪里.这是一个大量的数据,我想从我的日志中删除它.
这可能吗?
我正在使用Rails 4.0.4
actiondispatch ×10
ruby ×4
cookies ×2
actionmailer ×1
content-type ×1
cucumber ×1
factory-bot ×1
httprequest ×1
logging ×1
middleware ×1
rack-cors ×1
routes ×1
rspec2 ×1
symbols ×1
view ×1
webpacker ×1