Thursday, October 3, 2013

Using helper devise in other controller

Using helper devise in other controller

I am using devise gem for my rails app. I am trying to use
sign_in(resource_name, resource) in other controller(not devise
controller). I have been looking for this answer, but no luck. Anyone
knows how to do that? Thanks.

Wednesday, October 2, 2013

How to fully remove temporary elements?

How to fully remove temporary elements?

I am dynamically adding a 'div' node inside a function that will only be
needed temporarily. I have already used < parent >.removeChild to detach
it and then set it to null, but I am curious to know what happens to
unattached nodes created in a function when it goes out of scope?
If the nodes remain in memory but unattached:
A) Is setting to null even necessary or does it automatically go away on
return?
and if so is setting to null the proper way?
B) Does anything need to be done with its properties? (such as
node.style.position)
C) If it contained additional children, would they need to be handled
individually or would they go away when their unattached parent node is
set to null?
D) What tool(s) can be used to view these kinds of unattached resources?
Here is an example function for discussion purposes:
function dpi(){
var res={},
div=document.createElement("div"),
body=document.getElementsByTagName('body')[0]
div.style.position="absolute"
div.style.width="1in"
div.style.height="1in"
div.style.left="-100%"
div.style.top="-100%"
body.appendChild(div)
res["xdpi"]=div.offsetWidth
res["ydpi"]=div.offsetHeight
body.removeChild(div)
div=null
return res
}

min-width in IE compatibility mode

min-width in IE compatibility mode

Goal: Have buttons have a minimum width but expand when text is longer
than min width like in the case of other languages.
The problem is that in IE8 or 9 in compatibility mode, the buttons seem to
move outside of their container to the right. I unfortunately cannot
provide any code or link to jsfiddle since it does not work in IE8 compat
mode, but here are some pictures of the issue.
No min-width
Buttons shows normally, but obviously does not show the minimum width we
want.
With min-width
IE layout shows a width of 100px, which is what it should be, but the
button seems to move outside of the container.

Scope problems within angular directives

Scope problems within angular directives

I'm following the lessons on egghead.io
(http://egghead.io/lessons/angularjs-directive-to-directive-communication),
and I'm having some scope problems. When I mouse over <superhero
flash>flash</superhero>, I am getting a blank array instead of 'speed'.
However, when I add the flash directive to the second superhero directive,
it prints it correctly. I am wondering if there are any scope problems I
am having?
http://jsfiddle.net/9q6MG/
Console (on mouse over on flash)
Expected: 'speed'
Actual: []
http://jsfiddle.net/ewmCT/

Table should be only as wide as necessary

Table should be only as wide as necessary

I want a HTML <table> to be just the size it needs to be.
Without specifying anything it will span the whole width. Setting
width="auto" doesn't work.

Tuesday, October 1, 2013

z-index and opacity with one image partially on top of another, how can I remove the transparency?

z-index and opacity with one image partially on top of another, how can I
remove the transparency?

I have two images on my site, one is simply an image ( in the HTML file),
while the other is the background of a container (the main part of the
page) (defined in the CSS file as "background-image:url(x)") added to the
HTML file via a tag. The rest of the page has a background of #eeeeee
(slightly darker white).
The z-indexes of the two are set so the image is on top of the background
image, exactly what I want... However, I can see through the image to the
background image. This is because the has opacity:0.4 as a style
attribute. So it makes sense that it shows through to the background, but
is there any way to make the be transparent through to my #eeeeee
background?

$.post vs $.ajax throws invalid json primitive 'data'

$.post vs $.ajax throws invalid json primitive 'data'

WORKS NOT
$.post('Schoolyear/Create', { data: JSON.stringify({ schoolyearId: 1 }) });
throws exception internal server error 500: invalid json primitive 'data'
WORKS
$.ajax('Schoolyear/Create', { data: JSON.stringify({ schoolyearId: 1 }),
type: 'POST' });
Why can I not use the explicit $.post and have to write the type instead?

Why did the U.S. government shut down=?iso-8859-1?Q?=2C_if_the_Fed_was_providing_funding_through_the_bond_buyi?=ng program=?iso-8859-1?Q?=3F_=96_politics.stackexchange.com?=

Why did the U.S. government shut down, if the Fed was providing funding
through the bond buying program? – politics.stackexchange.com

I understand that the current Federal Bond Buying program ($80 billion a
month) is allowing a fixed supply of money to the American Government. If
this is the case, then why did the government "shut …

How does Ruby's .() operator work=?iso-8859-1?Q?=3F_=96_stackoverflow.com?=

How does Ruby's .() operator work? – stackoverflow.com

I recently came across some code using a method call consisting of the
format object.(arg1, arg2) without seeing a good explanation of how it
works. See this sample code: class TestServiceObject …