Ruby On Rails

    How to convert date to timestamp and timestamp to date in ruby on rails?

    You can do this simply
    #date to timestamp

    start_date = DateTime.now

    timestamp = start_date.to_time_to_i

    #Timestamp to date again

    start_date_again = Time.at(timestamp)

    `require': cannot load such file -- client_side_validations/formtastic (LoadError)

    The problem seems to be due to client_side_validations version

    so use

    gem 'client_side_validations', '3.1.0'

    in gemfile and run bundle update

    How to add html to link_to in ruby on rails

    To add html inside link_to use raw on title
    <%=link_to (raw("<span>Link Title</span>"), path) %>
    Removing Jetbrains IDE idea files git rm -r --cached .idea/

    expected Array (got Rack::Utils::KeySpaceConstrainedParams) Problem

    This is due to missing key in [] when you are creating form for child attributes. Multiple entries are there and this behaves as array instead of hash causing problem. Solution is to add key there you can use timestamp as ke as that is unique

    How to get key from value ruby on rails hash or array

    To get key from value you can use below code:
    testhash = {:active => 1, :blocked => 2, :pending => 3}

    testhash.map{ |k,v| v==2 ? k.to_s.capitalize!  : nil }.compact

    It will display result "Blocked"

    active_support/dependencies.rb:503:in `load_missing_constant': Load error in module

    This is due to missing module file like my_module.rb in my_module directory for Module named MyModule

    or

    Due to duplicate class existence

    How to use observers in Ruby on Rails

    We can use observers with model to seperate some of the required functionality on paticular action To create a observer create observer file in models directory for example i have to create a observer for User model i can name it user_observer.rb it will send email on registration i have already created a mailer CustomMailer just call it here passing user object in it
    # models/user_observer.rb
    class UserObserver < ActiveRecord::Observer

      def after_create(user)
        # Send Registration Email
        CustomMailer.registration_email(user).deliver
      end
    end
    To ena

    How to uninstall RVM Ruby Version Manager

    To uninstall RVM just execute following command in terminal use sudo rvm implode if don't have administrative previlages for the logged in user remove /etc/rvmrc and ~/.rvmrc after uninstalltion
    rvm implode
    # This will uninstall the RVM

    How to enable custom slugs options in latest version of refinerycms

    To enable custom slugs in refinerycms goto config/initializers/pages.rb you can see a variable use_custom_slugs uncomment that line and set that true if its false if its not there just add
    config.use_custom_slugs = true

    NoMethodError in nil class Ruby on Rails

    This error will come if you are missing method or don't have any record related to the path request so you need to handle this error simple add bang (!) in controller where you are getting data
    def request
        @request = Request.find_by_request_id!(params[:id])
        respond_to do |format|
           format.html {render :layout => "landing", :template => "requests/newrequest"}
           format.json { render :json => {:request => @request} }
        end
    end

    # ! rescue and  redirect to 404 page if no record exists for params[:id]