jump to navigation

Rails flash[:notice] problem

Posted by LJ Arthur Neil in : Ruby on Rails , add a comment

flash[:notice] is meant only for redirect action, because the message is only cleared after the redirected view request. So if you don’t redirect the request, and you click on the next request, that message will still be displayed.

But sometimes, we just want to display custom error messages only for current request without the redirection (esp. for non-ActiveRecord error messages). So the option is to use flash.now[:notice]. It clears the flash message at the end of current request (without redirection),

e.g.

def your_method
…..
flash.now[:notice] = ‘your message’
end

Running Rails code through cron job

Posted by LJ Arthur Neil in : Ruby on Rails , add a comment

Rails comes with a script/runner script that can be used to run the code in your Rails app. There’re many ways to organize your code to let this runner script execute it, but one obvious way is to write the code as a model’s action.
Here are quick steps for doing this:

1. Insert the code into an action of a model,

(E.g) Model.MyFunction, “MyFunction” must be defined as class method, “def self.MyFunction…”

2. In your cron job, add a line to run this at certain interval:

/usr/local/bin/ruby /path/to/your/app/script/runner -e production “Model.MyFunction”

You may need to change the ruby path on your system if it is different.

Joke of the day

Posted by LJ Arthur Neil in : Fun-and-morals , add a comment

A man was leaving a cafe with his morning coffee when he noticed a most unusual funeral procession A funeral coffin was followed by a second one about 50 feet behind the first.

Behind the second coffin was a solitary man walking with a black dog. Behind him was a queue of 200 men walking in single line. The man couldn’t stand his curiosity.

He approached the man walking with the dog, “I am so sorry for your loss, and I know now is a bad time to disturb you, but I’ve never seen a funeral like this with so many of you walking in single line. Whose funeral is it?

” The man replied, “Well, that first coffin is for my wife. ” What happened to her? ”

The man replied, “My dog attacked and killed her. ”

He inquired further, “Well, who is in the second coffin? ”

The man answered, “My mother-in-law. She was trying to help my wife when the dog attacked and killed her also. ”

A thoughtful moment of silence passes between the two men.Then the first one asks in excitement “Can I borrow the dog? ”

The man replied “Join the queue .”

Life is a gift

Posted by LJ Arthur Neil in : Fun-and-morals , add a comment

Today


Before you say an unkind word -Think of someone who can’t speak.

Before you complain about the taste of your food -Think of someone who has nothing to eat.

Before you complain about your husband or wife -Think of someone who’s crying out to GOD for a companion

Today


before you complain about life -Think of someone who went too early to heaven.

Before whining about the distance you drive -Think of someone who walks the same distance with their feet.

And when you are tired and complain about your job -Think of the unemployed, the disabled, and those who wish they had your job.

And when depressing thoughts seem to get you down -Put a smile on your face and think:you’re alive and still around.

Remember the past

Posted by LJ Arthur Neil in : Fun-and-morals , add a comment

There was a blind girl who hated herself because she was blind.
She hated everyone, except her loving boyfriend.
He was always there for her.

She told her boyfriend,’If I could only see the world, I will marry you.’
One day,someone donated a pair of eyes to her.
When the bandages came off, she was able to see everything,including her boyfriend.

He asked her,’Now that you can see the world,will you marry me?’
.
.
.
.

The girl looked at her boyfriend and saw that he was blind.

The sight of his closed eyelids shocked her.

She hadn’t expected that.

The thought of looking at them the rest of her life led her to refuse to marry him.

Her boyfriend left in tears and days later wrote a note to her
saying:

‘Take good care of your eyes, my dear, for before they were yours, they were mine.’

This is how the human brain often works when our status changes.

Only a very few remember what life was like before,and who was always by their side
in the most painful situations.



Page 1 of 2912345»...Last »