Is it possible to override default_scope in rails_admin? - rails-admin

For example, I have:
class Answer
include Mongoid::Document
default_scope where(status: "active")
end
However, when I have this class then none of my hidden answers show up in rails_admin. Any recommendations on this?

I would do this:
list
scopes [:unscoped, :nil, :scope1]

Related

Retrieve the attributes in a UML class diagram-jointjs

I would like to retrieve attributes and class name in UML class diagram using jointJS. Please help in this regard.
maybe you can use:
this.attr('.uml-class-name-text/text')
to get the class name and use
this.attr('.uml-class-attrs-text/text')
to retrieve attributes.
"this" is the object you selected, see below
var selected;
paper.on('cell:pointerdown', function(cellView) {
selected = cellView.model;
});
All the attributes of uml diagram is in "attribute" object, if you have created the graph then you can access it as follows:
graph.getCell("cell_id").attributes;
the cell_id is present in the id property of the graph.
Hope this helps!

Check the type of a property in neomodel

Is it possible to get the type of a property in neomodel?
For example something like this:
for n in MyNodeModel.properties:
if n == StructuredNode:
print('StructuredNode')
I hope my questions is clear...
Sure you just need to get the property object from the model:
if isinstance(MyNodeModel.your_property, StringProperty):
print("a string")
If this doesn't answer your question please open an issue on github

How do I find all elements which have a css class in coded ui?

I need to find all Html controls which have a given css class.
var htmlControl = new HtmlControl(document);
htmlControl.SearchProperties[HtmlControl.PropertyNames.Class] = #class;
var uiTestControlCollection = htmlControl.FindMatchingControls();
Using the class name works when there is just one css class on the control. If I have more than one css classes applied on the element, can I search for the element by specifying just one css class and not all of them?
Thanks
You can perform a partial match, like so:
htmlControl.SearchProperties.Add(HtmlControl.PropertyNames.Class, #class, PropertyExpressionOperator.Contains);
var uiTestControlCollection = htmlControl.FindMatchingControls();
The main draw back of this is that it is just a simple string compare. To illustrate, imagine you have two controls A and B. A has class "Test" and B has classes "testdiv topnav". Now if you perform a search for "test", both controls A and B will be selected.
To match a class exactly, you can provide a close as match as possible using the above method and write a helper function to:
Loop through the collection
Get the class of each control
Split the class string on the spaces
Loop through this array and test each for an exact match
Keep the elements where a class matches exactly
Note: This is clearly non-optimal - I'm all ears if someone has a better solution.
Cheers,
Seb

How can I find out if Class A directly inherits from Class B in c#?

Lets say Class A inherits from Class B which inherits from Class C. Class B directly inherits from Class C but Class A does not directly inherit from class C. I want to use some method like:
ClassA.DirectlyInheritsFrom(ClassC) //returns false
ClassB.DirectlyInheritsFrom(ClassC) //returns true
Can someone point me to something actually in the C# reflection libraries that accomplishes this?
Thanks!
How about:
return childType.BaseType == parentType;
(See Type.BaseType for details.)
That's assuming I've read your question correctly - please let me know if I misunderstood.

Rails3 get current layout name inside view

I have the answer for the Rails 2.X but not for Rails 3. How can I read the name of a current layout rendered inside a view.
My Rails2 question: Rails Layout name inside view
Thx.
Getting this to work in Rails 3.2 is a little more complicated than previously outlined. If your controller explicitly declares a layout, then the result of controller.send(:_layout) is a String, but otherwise it's an ActionView::Template. Try this:
module ApplicationHelper
def current_layout
layout = controller.send(:_layout)
if layout.instance_of? String
layout
else
File.basename(layout.identifier).split('.').first
end
end
end
in rails 5
This works for me:
def current_layout
layout = controller.class.send(:_layout)
if layout.nil?
default_layout
elsif layout.instance_of? String or layout.instance_of? Symbol
layout
else
File.basename(layout.identifier).split('.').first
end
end
For Rails 4:
controller.send(:_layout)
=> 'application'
For Rails 3.2:
controller.send(:_layout)
=> #<ActionView::Template:0x000000082bb788>
But controller.send(:_layout).identifier returns the fullpath:
/home/davidm/Documentos/Devel/myapp/app/views/layouts/application.haml
I think it should be in core, but for now you can make a helper method:
def current_layout
controller.send :_layout
end
it will return currently used layout name
I have used in Rails4 at view pages and got reuslt.
controller.send(:_layout)
I hope this help.
For rails 5:
controller.class.send(:_layout)
This does NOT work:
controller.send(:_layout)
You can do what I've done in my Ajax gem for Rails which is to wrap the _render_layout method:
ActionView::Base.class_eval do
def _render_layout_with_tracking(layout, locals, &block)
controller.instance_variable_set(:#_rendered_layout, layout)
_render_layout_without_tracking(layout, locals, &block)
end
alias_method_chain :_render_layout, :tracking
end
Then you can access the value that was set from your view (I'm pretty sure you have access to the controller there...) or in your controller in an after_filter, which is what I do.
I've written a custom RSpec 2 matcher which can be used to test layout rendering in Rails 3.
All the approaches in the previous answers try to guess the name via private methods, but there's no need to guess and can be easily accomplished with the public API:
class ApplicationController
layout :set_layout
attr_reader :layout_name
helper_method :layout_name
private
def set_layout
#layout_name = "application"
end
end
Override in any controller that won't use the standard layout:
class MyController < ApplicationController
private
def set_layout
#layout_name = "my_layout"
end
end
And now in your views:
<%= layout_name %>

Resources