I tried to upgrade Mindapp Gem from Rails 4 to Rails 5. There are a lots of codes like below need to be fixed because Rails 5.1 no longer support mass assignment to_bson directly.
Mindapp::Xmain.create :service=>service,
:start=>Time.now,
:name=>service.name,
:ip=> get_ip,
:status=>'I', # init
:user=>current_user,
:xvars=> {
:service_id=>service.id, :p=>params,
:id=>params[:id],
:user_id=>current_user.try(:id),
:custom_controller=>custom_controller,
:host=>request.host,
:referer=>request.env['HTTP_REFERER']
}
Then error:
DEPRECATION WARNING: Method to_bson is deprecated and will be removed in Rails 5.1, as `ActionController::Parameters` no longer inherits from hash. Using this deprecated behavior exposes potential security problems. If you continue to use this method you may be creating a security vulnerability in your app that can be exploited. Instead, consider using one of these documented methods which are not deprecated: http://api.rubyonrails.org/v5.0.2/classes/ActionController/Parameters.html
To comply with Rails 5.1 from this WARNING: I put params (without understand really) to:
Mindapp::Xmain.create(xmain_params)
def xmain_params
params.permit(
:service=>service,
:start=>Time.now,
:name=>service.name,
:ip=> get_ip,
:status=>'I', # init
:user=>current_user,
:xvars=> {
:service_id=>service.id, :p=>params,
:id=>params[:id],
:user_id=>current_user.try(:id),
:custom_controller=>custom_controller,
:host=>request.host,
:referer=>request.env['HTTP_REFERER']
}
)
end
Problem: It's not create as supposed to do.
This code (before modified) work in rails 4 but Warning in 5.0 and Now not work in Rails 5.1 all using Ruby 2.4.1.
What should I do/Thanks
And when tried
Mindapp::Xmain.create :service=>params.permit(service),
:start=>params.permit(Time.now),
:name=>params.permit(service.name),
:ip=>params.permit(get_ip),
:status=>params.permit('I'), # init
:user=>params.permit(current_user),
:xvars=> params.permit({
:service_id=>service.id, :p=>params,
:id=>params[:id],
:user_id=>current_user.try(:id),
:custom_controller=>custom_controller,
:host=>request.host,
:referer=>request.env['HTTP_REFERER']
})
Errors:
Mongoid::Errors::InvalidValue -
message:
Value of type ActionController::Parameters cannot be written to a field of type Hash
summary:
Tried to set a value of type ActionController::Parameters to a field of type Hash
resolution:
Verify if the value to be set correspond to field definition:
And try using params.
Mindapp::Xmain.create :service=>params.service,
:start=>params.Time.now,
:name=>params.service.name,
:ip=> params.get_ip,
:status=>params('I'), # init
:user=>params.current_user,
:xvars=> {
:service_id=>params.service.id, :p=>params,
:id=>params[:id],
:user_id=>params.current_user.try(:id),
:custom_controller=>params.custom_controller,
:host=>params.request.host,
:referer=>params.request.env['HTTP_REFERER']
}
Errors:
NoMethodError - undefined method `service' for #<ActionController::Parameters:0x007ff6b07158f0>:
actionpack (5.0.2) lib/action_controller/metal/strong_parameters.rb:646:in `method_missing'
app/controllers/mindapp_controller.rb:384:in `create_xmain'
The issue is :p=>params. I'm assuming params is a params object from the request. Under Rails 5.1, it will no longer support standard hash functions such as to_bson, which mindapp library appears to be using (or maybe one of its dependent libraries is using it).
A simple fix is probably to replace it with :p=>params.to_unsafe_hash or for a safer solution, :p=>params.permit(:foo, :bar) (whatever params should be used, these should possibly be checked/cleansed first).
Related
Note: ruby 2.0.0p481, Rails 4.0.13
Execute : RAILS_ENV=development bundle exec rake assets:precompile
Trace:
DEPRECATION WARNING: Support for Rails < 4.1.0 will be dropped.
(called from at
/host_share/project/config/application.rb:9) rake aborted!
Less::ParseError: Cannot call method 'split' of undefined (in
/host_share/project/app/assets/stylesheets/main.css.less) at
/home/vagrant/.rvm/gems/ruby-2.0.0-p481/gems/less-2.6.0/lib/less/js/lib/less/parser.js:604:31
/home/vagrant/.rvm/gems/ruby-2.0.0-p481/gems/less-2.6.0/lib/less/parser.rb:100:in
`block in to_css'
I dont know whats wrong ... please help me..
The error is quite clear here: In your app/assets/stylesheets/main.css.less you are doing a .split() operation on an undefined object, hence this is raising an error. Go in that file, search for the .split() method and check why the object you are calling this method on is not defined.
Go to your app/assets/stylesheets/main.css.less search for split. Remove split from the file and inspect the object you're calling split on to see if it's not nill
After the Swift 3 update, I'm having some trouble getting my app to compile. Most of the errors are pretty simple to fix, but I'm running into a few in particular with AWS. Is there some sort of updated AWS SDK for Swift 3? I've tried to look it up, but haven't found one. In any case, the two main errors I'm having trouble resolving are as follows:
"Type 'IdentityProviderManager' does not conform to protocol AWSIdentityProviderManager." This is for a class I created following a tutorial to set up logins through AWS Cognito. The code is:
class IdentityProviderManager: NSObject, AWSIdentityProviderManager{
var tokens : [NSString : NSString]?
init(tokens: [NSString : NSString]) {
self.tokens = tokens
}
#objc func logins() -> AWSTask<AnyObject> {
return AWSTask(result: tokens as AnyObject)
}
}
In the AWS documentation for AWSIdentityProviderManager, it says that the only required function is logins, which I have. Is there a simple way to resolve this that I'm missing?
The other error is in my LoginViewController class: "Type 'LoginViewController' does not conform to protocol 'AWSCognitoIdentityPasswordAuthentication'." Here the issue seems a bit more clear, since the documentation says that getPasswordAuthenticationDetails() is a required method and XCode seems to have changed this method to getDetails() when updating to Swift 3, unless I'm mistaken and it wasn't there to begin with or something. In any case, autocomplete doesn't give me the original method and I can't seem to make the class conform to the protocol.
Apologies if the answer is already in documentation somewhere, but as far as I can tell it seems like the AWS SDK (at least the version that I have) is somehow incompatible with Swift 3. Is there something I can do to resolve these errors?
Nevermind, it turned out XCode just wasn't showing me the option to make the changes I needed. The automatic fix implemented slightly different versions of the required functions and everything ended up working.
I am facing a weird error within my codebase currently. You can see the full ZF2s project code on my github right here. <- there's a link
I'm having a Module set up with two Entities (X and Y). Entity_X contains a reference to Entity_Y via (targetEntity="Entity_Y"). The Error persist with the FQCN or just the CN itself.
Entity_X:
id int PK,
id_Y int FK,
text varchar
Entity_Y:
id int PK,
text varchar
When loading Entity_Y first and then Entity_X everything is working fine. This remains true for both StandardAutoloader and ClassMapAutoloader. However: when loading Entity_X first with ClassMapAutoloader present, i will be seeing the following error:
Fatal error: Cannot redeclare class Kennzahlen\Entity\Referenzwert (Entity_Y)
in \module\Kennzahlen\src\Kennzahlen\Entity\Referenzwert.php
on line 13
Loading Entity_X first with StandardAutoloader works without any problems, too.
Update
The Problem appears to be within ZF2s ClassMapAutoloader (or Autoloading-Mechanism in General). My Module used the ClassMapAutoloader and using this i've gotten the above mentioned error. When removing the ClassMapAutoloader and simply using the StandardAutoloader, the error vanished into thin air. Thanks to #ocramius and all others i've botheres with this :)
I'm writing a failing test case to try and solve this in doctrine/common. The problem seems to be that silent autoloaders (as explained by #Xerkus) are not compatible with doctrine/common itself. To solve that, use a StandardAutoloader from ZF2 (or from composer) instead of using the ClassMapAutoloader. This will solve the issue until a patch is ready.
Update: patch is being suggested at doctrine/common#216
i have no knowledge of doctrine, but i browsed through source and i think i found issue:
https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/ClassLoader.php#L224
here, this code expects that autoloader will return value evaluated to true, but that is not requirement of spl autoload mechanism, therefore autoloader can return NULL,
To check if i am correct, in in your project in doctrine replace line 224 in Doctrine/Common/ClassLoader.php
} else if ($loader[0]->{$loader[1]}($className)) {
with
} else if ($loader[0]->{$loader[1]}($className) && class_exists($className, false)) {
Ans see if issue is fixed, if i am correct - then report bug to doctrine project
What is the correct way to use hogan.js with express.js?
I've tried the following:
var hogan = require('hogan.js')
...
app.set('view engine', 'hogan');
followed by
app.register('.hogan', hogan);
But I end up with the following error:
500 Error: Cannot find module 'hogan'
TJ put out a library called consolidate.js ( https://github.com/visionmedia/consolidate.js ) but I'm having trouble getting it to work with Express 2.5.8. After spending the day trying to figure this out I also came across a library called hulk-hogan.js ( https://github.com/quangv/hulk-hogan ) and another called hogan-express ( http://allampersandall.blogspot.com/2011/12/hoganjs-expressjs-nodejs.html ). But, do I really need all that?
If the solution can not be as simple as setting the templating engine with app.set() and app.register(), it would be great if someone could help me understand why. I'm using Hogan on the client and it's working great, it would just be so much better if I could also use it on the server.
UPDATE: Turns out there are two issues here.
While this is not causing the 500 error, Express does not work with Hogan out of the box (see: Linus G Thiel's answer below)
What seems to be causing the 500 error is that I'm using a virtual host and when I call res.render(), my res.render() call is actually calling the res.render() of a different virtual host on my same server.
Adding the full Express error dump. It looks like my app ('dataviz') is trying to use the render call from a different app ('datavizblocks')? Again, the two apps are virtual hosts on the same server.
dataviz 8000
Error: Cannot find module 'hogan.js'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at View.templateEngine (/localhost/datavizblocks/node_modules/express/lib/view/view.js:134:38)
at Function.compile (/localhost/datavizblocks/node_modules/express/lib/view.js:68:17)
at ServerResponse._render (/localhost/datavizblocks/node_modules/express/lib/view.js:417:18)
at ServerResponse.render (/localhost/datavizblocks/node_modules/express/lib/view.js:318:17)
at /localhost/dataviz/routes/section.js:325:7
at callbacks (/localhost/dataviz/node_modules/express/lib/router/index.js:272:11)
dataviz 8000
Error: Cannot find module 'hogan.js'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at View.templateEngine (/localhost/datavizblocks/node_modules/express/lib/view/view.js:134:38)
at Function.compile (/localhost/datavizblocks/node_modules/express/lib/view.js:68:17)
at ServerResponse._render (/localhost/datavizblocks/node_modules/express/lib/view.js:417:18)
at ServerResponse.render (/localhost/datavizblocks/node_modules/express/lib/view.js:318:17)
at /localhost/dataviz/routes/section.js:325:7
at callbacks (/localhost/dataviz/node_modules/express/lib/router/index.js:272:11)
The 500 error goes away when I comment out the datavizblock vhost, or when I switch the order of the vhost declarations around to have the dataviz vhost declared after datavizblocks vhost (of course, this then causes problems for the datavizblocks vhost)
Apologies ahead of time for the confusing question, but I was really confused when I came across this issue and never expected that switching to Hogan would have conflicts with virtual hosting.
The issue is that Express requires an interface from template engines, where the template engine is expected to have a compile method, and that compile method is expected to return a function which can be called with the template data.
Hogan has a compile method, but it returns a template object which has a render method. You need to expose that render method to Express, and this seems to be what the hogan-express module does. It shouldn't have to be that involved though, I think this will work (I have only tested it slightly, might be some gotchas?):
var express = require('express'),
hogan = require('hogan.js'),
app = express.createServer();
app.set('view engine', 'hogan');
app.register('hogan', {
compile: function() {
var t = hogan.compile.apply(hogan, arguments);
return function() {
return t.render.apply(t, arguments);
}
}
});
Basically, we are just creating our own object that has a compile method that maps to Hogan's render method.
This expects your templates to be named e.g. index.hogan.
As Linus said, you need an adapter to use Hogan with Express. consolidate works fine as long as you don't need support for partials or layouts (they are working on it but I don't know when it will be ready).
I was in the same spot you're in a few months ago and found hulk-hogan's and express-hogan's documentations to be quite confusing so I coded my own wrapper that has support for partials, layouts, template caching and can be plugged in Express in one line of code. You can check it out here: h4e - templating with hogan for express
I am receiving the following exception when trying to run my unit tests using .net 4.0 under VS2010 with moq 3.1.
Attempt by security transparent method
'SPPD.Backend.DataAccess.Test.Specs_for_Core.When_using_base.Can_create_mapper()'
to access security critical method
'Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(System.Object)'
failed.
Assembly
'SPPD.Backend.DataAccess.Test,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' is marked with
the
AllowPartiallyTrustedCallersAttribute,
and uses the level 2 security
transparency model. Level 2
transparency causes all methods in
AllowPartiallyTrustedCallers
assemblies to become security
transparent by default, which may be
the cause of this exception.
The test I am running is really straight forward and looks something like the following:
[TestMethod]
public void Can_create_mapper()
{
this.SetupTest();
var mockMapper = new Moq.Mock<IMapper>().Object;
this._Resolver.Setup(x => x.Resolve<IMapper>()).Returns(mockMapper).Verifiable();
var testBaseDa = new TestBaseDa();
var result = testBaseDa.TestCreateMapper<IMapper>();
Assert.IsNotNull(result); //<<< THROWS EXCEPTION HERE
Assert.AreSame(mockMapper, result);
this._Resolver.Verify();
}
I have no idea what this means and I have been looking around and have found very little on the topic. The closest reference I have found is this http://dotnetzip.codeplex.com/Thread/View.aspx?ThreadId=80274 but its not very clear on what they did to fix it...
Anyone got any ideas??
In the AssemblyInfo.cs of the referenced project add this following line
[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]
MSDN: "The .NET Framework version 4 introduces new security rules that affect the behavior of the AllowPartiallyTrustedCallersAttribute attribute (see Security-Transparent Code, Level 2). In the .NET Framework 4, all code defaults to security-transparent, that is, partially trusted. However, you can annotate individual types and members to assign them other transparency attributes."
Haven't come across this myself, but perhaps you have imported somehing from a 3.5 project.
Check out these links:
Security Changes in the .NET Framework 4
Security-Transparent Code, Level 2
AllowPartiallyTrustedCallersAttribute Class
This has been fixed in the latest version of Moq (it was a fix in DynamicProxy actually).
Please give the latest v4 Beta a try.
http://moq.me