Rails gem to show a form for callback request in modal
Ruby HTML Other
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
bin
config
lib
test
.gitignore
Gemfile
Gemfile.lock
MIT-LICENSE
README.md
Rakefile
callback_request_bootstrap-0.0.1.gem
callback_request_bootstrap-0.0.2.gem
callback_request_bootstrap.gemspec

README.md

Callback Request with Bootstrap 3

Rails gem to show a form for callback request in modal. To be used with Bootstrap 3 and simple_form.

Requests for phone callbacks are stored in database.

Dependencies

  • jQuery (jquery, jquery_ujs). use gem jquery-rails
  • bootstrap 3 - gem boostrap-sass
  • form - gem simple_form

Installation

Gemfile:

gem 'callback_request_bootstrap'

gem 'simple_form'
bundle install

install using generator:

rails g callback_request_bootstrap:install

This will add the migrations.

Migrate the database:

rake db:migrate

It will add table 'requests' to the database.

Your application should have jquery, jquery_ujs and bootstrap.js installed. Your application.js might be:

//= require jquery
//= require jquery_ujs

//= require bootstrap
or if you want to include only javascript for modal
//= require bootstrap/modal

mount engine in config/routes.rb:

Rails.application.routes.draw do

  mount CallbackRequestBootstrap::Engine => "/callback"

  ..
end

Link to show form in modal:

<%=link_to_callback_modal "Request callback", '#', :class=>'btn' %>

This helper generates a link with css class 'callback_link'.

or add class 'callback_link' to your link:

=link_to 'Request callback', '#', :class=>'btn btn-primary callback_link'

include on page (usually at the end of the page where you place the link):

<%= render 'callback_request_bootstrap/requests/js_modal'%>

This will add necessary scripts for modal.

Options

Autoclose

To close modal after a request is sent, use option 'autoclose' for a link:

<%=link_to "Show modal with autoclose", '#', :class=>'btn btn-default callback_link', :data=>{'autoclose'=>5} %>

This will close modal in 5 seconds.

Customization

Form

Use generator to copy views to your application. Edit views in /app/views/callback_request_bootstrap/.

If you want to edit fields in the form, then edit view '_form.simple_form.html.erb'.

Localization

Copy file config/locales/callback_request.en.yml to your application in config/locales/callback_request.LANG.yml. Edit the file.

Callbacks

Callback after a new request created

# config/initializers/callback_request.rb

module CallbackRequestPatch
  extend ActiveSupport::Concern

  included do
    after_create :_my_after_create

  end


  def _my_after_create
    # your code

    logger.debug "callback request created"



  end

end

CallbackRequestBootstrap::Request.send(:include, CallbackRequestPatch)