Subscribe Rss:

Wednesday, March 20, 2013

Undefined local variable or method `current_user' - Devise

I was working with devise for one my project.Previously i used to create the model as User by default, thereby i didn't found any errors during signing.

But when i had my model as connectz_user i was getting the error "undefined local variable or method `current_user'"
Later, i checked with the devise mail listing group and they informed me to go with current_connectz_user.After implementing the later change on my views, i am not finding the error on my app

Saturday, January 26, 2013

Jquery submission of values on keypress

This was a interview question, where i was asked to create a todo application with any JavaScript framework.



Requirement was to add the daily task and the code shouldn't have any form and submit button.Also the task to be added with the enter key press.

On searching found couple of articles one about the prevention of form on enter key press and other from stackoverflow submitting a form on 'Enter' with jQuery?

Then i come up with my code.

JS Code


$('input').bind("keypress",function (e) {
if (e.which == 13) {
/**Append Logic **/
e.preventDefault();
}
});



JSFiddle

Sunday, January 13, 2013

Write javascript for loop in ruby

The JavaScript For Loop resembles the for loop you may have seen in many other programming languages. It is used when you need to do a set of operations many times, with an increment of some kind after each run through the block of code.

for(i=0;i<=10;i++)
{
alert("Counter i = " + i);
}
For loop in ruby
for i in 0..10
   puts "counter i is #{i}"
end
Now i had a javascript for loop with variable incremented to 2
for ( var i = 0; i <=10; i += 2 )
{
alert("Counter i = " + i);
}
Now in ruby i can go with step instead of default for
0.step(10,2) { |i| puts i }
There was an error in this gadget