Friday 25 August 2017

Fetch Full Url from String by Javascript

 
//Remove Html code from string 
var textString = code.replace(/<\/?[^>]+(>|$)/g, " ").replace(/^(&nbsp;|nbsp;)+/g, '').trim(); //Match full url and generate a array
var urls = textString.match(/\b(http(s)?(:\/\/))?(www.)?[a-zA-Z0-9-_.]+(.[a-zA-Z0-9]{2,}).*?(\.\w+)([-a-zA-Z0-9:%_+.~#?&\/\/=]*)/ig);

//Remove content before http
var url =  /http(.+)/.exec(urls[0])[0];

Wednesday 15 March 2017

Slider

slick
 
 
http://amazingslider.com 

Auto suggest in rails for fields it so simple by help of data-autocomplete parameter

 
Define data-autocomplete field in text field and then path of the function with parameters: 
 
=f.text_field :user_search,"data-autocomplete" => autocomplete_user_name_path(:user_type=>"Admin")
 
 
Controller Action:
 
def autocomplete_institution_name
  term = params[:term]
  user_type = params[:user_type]
  
  users = User.where('name LIKE ? AND user_type = ?', "%#{term}%",user_type).order(:name).all 
  render :json => users.map { |user| {:id => user.id, :label => user.name, :value => user.name} }
end 
 

Thursday 2 March 2017

Ruby On Rails Form with Ajax by remote => true

<<<==============================Ruby Ajax Form Submitting Syntax =======================>>> 
 
=form_for @modelObject, :remote => true,:html => {:'data-type' => 'json',:onSubmit=>"checkform()"}
,:url => url_path([@paramsinUrl]) do |f|
 
 
 
 
<<<<=======================================Controller==============================>
 
def create
 @modelObject =  ModelObjectClass.new(params['params_name']) 
 respond_to do |format|
   if @modelObject.save
       format.html { redirect_to :back }
       format.json { render :json => {:status=>"success",:message=>'Added Sucessfully.'} } 
   else
     format.html { redirect_to :back }
     format.json { render :json => {:status=>"error",:message=>'Error Message.'} } 
   end 
 end 
 
end 
 
 
 
<<<<==================================Javascript======================================>
 
$("#form_id").live("ajax:beforeSend", function(e, xhr, settings) {
  

});
$("#new_manual_air_booking").live("ajax:success", function(e, data, status, xhr) {
   alert("Added");
   render_time_slot(DI.day_wrapper_id,DI.day_date,DI.trip_id);
   $("#daily_itinerary_event_model").html('');

}).live("ajax:error", function(e, xhr, status, error) {
    alert("Error");
});  

 


=======================================OR================================================ 
 live => on

Instead of live you can use on because live deprecated few year back, syntax for using on is:
 
$(document).on('ajax:beforeSend','#form_id',function(e, xhr, settings) {
  

}); 
 
 Instead of document you can wright parent element id of element which we are going to target.
 

Thursday 23 February 2017

Ruby on Rails Developer need to have aware about


RoR experience in 3.x, 4.x, 5 beta
- Ruby 2.x
- Rspec, Mocha, Cucumber
- Postgres, RDS
- Passenger, Puma
- AngularJS/NodeJS
- Redis, SQS
-Rails caching 

RSpec and Resque
Demonstrated strengths for JAVA 7 and above, Core Java, Advance Java, Jersey Framework, JMS, JSON, XML, 
 
RESTFUL and SOAP web services

Monday 13 February 2017

RUBY On RAILS

What is indexing, trigger in mysql?


What is curl, why we use it, how to use it?


What is Static Class and Static method, define it and how to use that?


Rails asset pipeline: Why things break in production and what precompilation does to your assets

Rails asset pipeline: Why things break in production and what precompilation does to your assets

When you work with a Rails 3.1+ application, you will be working with the asset pipeline. The asset pipeline is awesome until you deploy. Then it will be less so if you haven't done everything as the pipeline expected it from you.

The problem

When using the asset pipeline your assets (images, javascripts, stylesheets, fonts) live in folders inside app:
COPY
app/assets/fonts app/assets/images app/assets/javascripts app/assets/stylesheets
With the asset pipeline, you can use the full power of Ruby to generate assets. E.g. you can have ERB tags in your Javascript. Or you can have an ERB template which generates Haml which generates HTML. You can chain as many preprocessors as you want.
When you deploy, Rails runs assets:precompile which precompiles all assets into static files that live in public/assets. This way you have all the performance of static files with all the expressiveness of Ruby.
Unfortunately, the path of every single file changes during precompilation. This means that you have to be a bit careful how you reference assets.
COPY
.tile background-image: url('../images/foo.png')
won't work any longer, because there is no public/assets/images. foo.png now lives directly in public/assets.

Example

COPY
app/assets/fonts app/assets/fonts/fonts_root.css app/assets/fonts/fonts_root.js app/assets/fonts/fonts_root.png app/assets/fonts/fonts_root.ttf app/assets/fonts/subfolder app/assets/fonts/subfolder/fonts_subfolder.css app/assets/fonts/subfolder/fonts_subfolder.js app/assets/fonts/subfolder/fonts_subfolder.png app/assets/fonts/subfolder/fonts_subfolder.ttf app/assets/images app/assets/images/images_root.css app/assets/images/images_root.js app/assets/images/images_root.png app/assets/images/images_root.ttf app/assets/images/subfolder app/assets/images/subfolder/images_subfolder.css app/assets/images/subfolder/images_subfolder.js app/assets/images/subfolder/images_subfolder.png app/assets/images/subfolder/images_subfolder.ttf app/assets/javascripts app/assets/javascripts/application.js app/assets/javascripts/javascripts_root.css app/assets/javascripts/javascripts_root.js app/assets/javascripts/javascripts_root.png app/assets/javascripts/javascripts_root.ttf app/assets/javascripts/subfolder app/assets/javascripts/subfolder/javascripts_subfolder.css app/assets/javascripts/subfolder/javascripts_subfolder.js app/assets/javascripts/subfolder/javascripts_subfolder.png app/assets/javascripts/subfolder/javascripts_subfolder.ttf app/assets/stylesheets app/assets/stylesheets/application.css app/assets/stylesheets/stylesheets_root.css app/assets/stylesheets/stylesheets_root.js app/assets/stylesheets/stylesheets_root.png app/assets/stylesheets/stylesheets_root.ttf app/assets/stylesheets/subfolder app/assets/stylesheets/subfolder/stylesheets_root.png app/assets/stylesheets/subfolder/stylesheets_subfolder.css app/assets/stylesheets/subfolder/stylesheets_subfolder.js app/assets/stylesheets/subfolder/stylesheets_subfolder.ttf
This precompiles into this (fingerprinted and compressed files removed for clarity):
COPY
public/assets/application.css public/assets/application.js public/assets/fonts_root.png public/assets/fonts_root.ttf public/assets/images_root.png public/assets/images_root.ttf public/assets/javascripts_root.png public/assets/javascripts_root.ttf public/assets/stylesheets_root.png public/assets/stylesheets_root.ttf public/assets/subfolder public/assets/subfolder/fonts_subfolder.png public/assets/subfolder/fonts_subfolder.ttf public/assets/subfolder/images_subfolder.png public/assets/subfolder/images_subfolder.ttf public/assets/subfolder/javascripts_subfolder.png public/assets/subfolder/javascripts_subfolder.ttf public/assets/subfolder/stylesheets_root.png public/assets/subfolder/stylesheets_subfolder.ttf

What has happened?

  1. All asset folders (app/assets/images, app/assets/stylesheets, app/assets/fonts, etc.) are merged into one folder:public/assets.
  2. Subfolders are also merged into public/assets. That means both app/assets/javascripts/subfolder/* andapp/assets/stylesheets/subfolder/* now live in public/assets/subfolder/*
  3. All CSS files are concatenated into one file (public/assets/application.css). With the default manifest inapp/assets/stylesheets/application.css, stylesheets in app/assets/stylesheets/**/*.css are concatenated. Sopublic/application.css has the following content:
    COPY
    /* content from app/assets/stylesheets/stylesheet_root.css */ /* content from app/assets/stylesheets/subfolder/stylesheet_subfolder.css */
  4. All Javascript files are concatenated into one file in root (public/assets/appliction.js). With the default manifest inapp/assets/javascripts/application.js, Javascripts in app/assets/javascripts/**/*.js are concatenated. Sopublic/application.js has the following content:
    COPY
    /* content from app/assets/javascripts/javascripts_root.js */ /* content from app/assets/javascripts/subfolder/javascripts_subfolder.js */

What will break after precompilation?

  • Stylesheets, that used url(../images/foo.png)-style tags
  • @font-face definitions that used url('fonts/bar.ttf')-style tags

How can I fix my stylesheets?

  • Do not use url(../images/foo.png). 
    This is plainly wrong, since from your browser's point of view, your stylesheet lives at /assets/application.css and your image at /assets/foo.png. I have no idea why it works in development in the first place. Simply use the SASS helper:
    COPY
    .tile background-image: image-url('foo.png')

How can I fix my font definitions?

  • With the Asset-Pipeline fonts are stored in app/assets/fonts. 
    Depending on your rails version, you may need to add
    COPY
    config.assets.paths << Rails.root.join("app", "assets", "fonts")
    to your config/application.rb
  • Do not use src: url(...) in your @font-face definitions.
    Again instead use a sass-helper: src: font-url(...)
  • Maybe the referenced paths need adjustment. If before it was src: url(fonts/...) now the leading fonts/ directory needs to be removed, because the fonts are compiled to the assets folder by the asset-pipeline.

https://makandracards.com/makandra/8951-rails-asset-pipeline-why-things-break-in-production-and-what-precompilation-does-to-your-assets 

Ruby How to use Haml in your helpers

How to use Haml in your helpers

You know those helper methods that just render some HTML but look weird because of content_tags all over the place? You could also use Haml instead.

Example

Consider the following helper.
COPY
def greeting message = ''.html_safe message << 'Welcome to ' message << content_tag(:span, Rails.env, class: 'greeting--location') content_tag :div, message, class: 'greeting' end
That looks clumsy and is hard to read.
Wouldn't it be nicer to say something like this?
COPY
def greeting render_haml <<-HAML .greeting Welcome to %span.greeting--location = Rails.env HAML end
It would be, and you can have it, too. You simply need to define render_haml as a helper method:
COPY
def render_haml(haml, locals = {}) Haml::Engine.new(haml.strip_heredoc, format: :html5).render(self, locals) end
Note how we pass the helper method's view context (self). This means that all of your other helper methods will be available to your Haml fragment.
Also note that you can pass locals to your Haml templates as usual:
COPY
def greet(someone) render_haml <<-HAML, name: someone Hello %strong = name HAML end
E

Sunday 12 February 2017

RubyMine tricks

1) pressing Shift twice
Have you tried the Search everywhere dialog? You can open it by pressing Shift twice.

2)

RubyMine: Set specific Ruby version per project

If your project uses another version than your default Ruby, RubyMine will give you incorrect inspections, for example.\
Here is how to switch which Ruby you use in RubyMine.
  1. File → Settings (Or press Ctrl+Alt+S)
  2. Select "Ruby SDK and Gems" from the left pane
  3. Switch your "Ruby interpreter".
Though it may seem you are changing a global setting here, this is in fact a per-project setting, as are all things you change in the "Project Settings [your_project_name]" area of the global settings dialog.
When you switch to another project, RubyMine will give you inspections and alike using that project's Ruby settings.

jQuery: When to use $(document).ready() and when $(window).load()

Summary

jQuery offers two methods to execute code and attach event handlers: $(document).ready and $(window).load.

$(document).ready()

The document ready event fired when the HTML document is loaded and the DOM is ready, even if all the graphics haven’t loaded yet. If you want to hook up your events for certain elements before the window loads, then $(document).ready is the right place.
Code:
$(document).ready(function() {
    // document is loaded and DOM is ready
    alert("document is ready");
});

$(window).load()

The window load event fired a bit later, when the complete page is fully loaded, including all frames, objects and images. Therefore functions which concern images or other page contents should be placed in the load event for the window or the content tag itself.
Code:
$(window).load(function() {
    // page is fully loaded, including all frames, objects and images
    alert("window is loaded");
});