Gurad FATAL: Listen error

Tuesday, February 9, 2016 · Posted in ,

While using guard with Rails 4, I have faced an error:

FATAL: Listen error: unable to monitor directories for changes.


Below command in Debian system work fine for me:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

I hope this helps.

jQuery Ajax Rails 3 - WARNING: Can't verify CSRF token authenticity

Tuesday, September 17, 2013

 WARNING: Can't verify CSRF token authenticity

This warning appears while I'm trying to do jQuery ajax request.

I have faced this issue while upgrading my older rails app to rails 3.2.

This issue solved by adding bellow lines in head section in layout of application for me.

    <%= csrf_meta_tag %>

    <%= javascript_tag do %>
      jQuery(document).ajaxSend(function(e, xhr, options) {
       var token = jQuery("meta[name='csrf-token']").attr("content");
        xhr.setRequestHeader("X-CSRF-Token", token);
      });
    <% end %>

The session was being reset in each ajax request (GET, POST, PUT, DELETE).
Adding the above mentioned code resolved my issue.

How to convert Time from/to epoch time in ruby

Monday, April 15, 2013 · Posted in , , ,

In ruby, we can find time from/to epoch time as below:

To Epoch Time:

To find current epoch time in seconds (10 digit) use below code,
    current_epoch_time =( Time.now.to_i)
                          or
    current_epoch_time =( Time.now.to_f).ceil

To find current epoch time in mili-seconds (13 digit) use below code,
    current_epoch_time =( Time.now.to_f*1000).ceil

From Epoch Time:

If we want Time from epoch time then use below code,

begin
   Time.at(current_epoch_time)
rescue RangeError => e
   Time.at(
current_epoch_time / 1000)
end


In above code,
1. current_epochtime is in integer.
2. If epochtime is in miliseconds (13 digit) then it will raise RangeError.
3. We have catch RangeError and find datetime accordingly.


I hope it's useful to work with epoch time in ruby.


Powered by Blogger.