In one of my recent project, I need to implement an autocomplete in active_admin interface to select one or more users from the user list. I tried googling on this and zeroed in on the library Chosen.Chosen by default supports multiple select, selected state.Chosen is available as a gem for Ruby on Rails which fits well with Asset Pipeline.
Include Chosen gem in your Gemfile.
1
gem ‘chosen-rails’
Once the gem is installed, include chosen javascript assets to your js file.
1
//= require chosen-jquery
In /app/admin/modelname.rb
12345678910
ActiveAdmin.register Modlename do
#Customize creates and edit form
form do |f|
f.inputs do
f.input :name
f.input :othermodel, :input_html => { :class => "chosen-input" } # other model with has_many relation ship
end
f.buttons
end
end
Then, include Chosen stylesheet assets to your css file.
1
*= require chosen
To include more details check Here
Thats it, you will have a nice autocomplte with multiselect . Happy coding…
Comments
Lobna Mohamed
Thanks for the good post, but does not save data to the database I guess it related to permit_params I am trying this permit_params :name, :othermodel_ids but still not working, have you another idea??
If Kannel is configured so that the bearerbox, wapbox and/or smsbox log to file each of these log files will continue to grow unless administered in some way. One way of reducing logs is by change log level. kannel allow to have 5 log-level ( 0 - debug, 1 - info, 2 - warning, 3 - error, 4 - panic). We can change log level by editing log-level component in configuration file and also done by admin HTTP command without restaring bearerbox.
Another way of administering log files is to ‘rotate’ the logs on a regular basis using a tool such as logrotate. A sample logrotate script is shown below.
Setup Logrotate
Step 1 : If logrotate is not already on your VPS, install it now.
1
sudo apt-get install logrotate
Step 2 : Add following script in file /etc/logrotate.d
In this example the Kannel log files found in /var/log/kannel are rotated and compressed daily over 365 days. To verify if a particular log is rotating or not and to check the last date and time of its rotation, check the /var/lib/logrotate/status file.
SQL box is a special Kannel box that sits between bearer box and SMS box and uses a database queue to store and forward messages. Messages are queued on a configurable table (defaults to send_sms) and moved to another table (defaults to sent_sms) afterwards.
After installing gateway, we need to compile SQL box.
Steps:
1 - cd to directory where Kannel is unzipped and then type the following commands
1234
cd addons/sqlbox/
sudo ./bootstrap
sudo ./configure --with-kannel-dir=/usr/local/kannel-1.5.0/
sudo make bindir=/usr/local/kannel/kannel-1.5.0/
2 -Create a file named smsbox.conf and the following configuration
1234567891011121314151617181920212223
#SQL BOX CONFIG
group = sqlbox
id = sqlbox-db
smsbox-id = sqlbox
global-sender = ""
bearerbox-host = localhost
bearerbox-port = 13010
smsbox-port = 13020
smsbox-port-ssl = false
sql-log-table = sent_sms
sql-insert-table = send_sms
log-file = "/var/log/kannel/kannel-sqlbox.log"
# Database connection examples. Please uncomment as needed
# Example MYSQL Connection
group = mysql-connection
id = sqlbox-db
host = localhost
username = username
password = password
database = kannel_db
3 - create send_sms table using following sql command
Example
As when you’re using the sendsms interface, you don’t need to specify all the columns in order to succesfully enqueue a message.
Here’s an example query you can use to send a simple message using Sqlbox:
The former example would send a message with text “Hello world” to number “9995323922”. If possible, the sender would be set to “TESTID”.You can add other parameters to specify routing, charset encoding and any other settings your setup may require
If you are keen to learn more about this , Refer Here
Last few months I have been facing lots of issues in Kannel SMS gateway.Some time sms are getting queued up, in some other time smsc went to the reconnecting stage. I searched for a tool which will monitor Kannel status unfortunately I didn’t find a tool to monitor and give an alert. so decided to write a tool which will monitor Kannel activities.
1
kannel_monitor 0.0.2
This gem will monitor
kannel status
kannel sms queue
smsc status
smsc queue and will send a email alerts when something went wrong.
Just install gem in server using
1
gem install kannel_monitor
run monitoring activity using command
1
kannel_monitor 'path to kannel_monitor.yml'
Example of yml file is given Here.
you need to set a crone job to run this in a specific intervals. If a smsc is permanently reconection stage and you don’t want to monitor that smsc, then you can skip that particular smsc by adding in sms_to_be_skipped
Writing a Ruby Gem was my long time wish, but i couldn’t find an idea to make a gem. Finally got it, for which i didn’t find a gem, a generator which will automatically generate a custom code for handling 404 and 500 errors and pages in rails application (Thanks to Sreekanth for noting there is no gem for this taks). Here it is
1
rails_error_pages 1.0.5
How to use :
Simply add it to your Gemfile and bundle install.
1
gem 'rails_error_pages'
Next step is to use a generator, to add auto generated code into our application using
1
rails g rails_error_pages
That’s it! run your application and try with a false URL.
To store DLR information into a MySQL database you may use the dlr-storage = mysql configuration directive in the core group.In addition to that you must have a dlr-db group defined that specifies the table field names that are used to the DLR attributes and a mysql-connection group that defines the connection to the MySQL server itself.
Here is the example configuration
12345678910111213141516171819202122
group = core
.........
dlr-storage = mysql
group = mysql-connection
id = mydlr
host = localhost
username = foo
password = bar
database = dlr
max-connections = 1
group = dlr-db
id = mydlr
table = dlr
field-smsc = smsc
field-timestamp = ts
field-destination = destination
field-source = source
field-service = service
field-url = url
field-mask = mask
field-status = status
field-boxc-id = boxc
Kannel is an open source WAP gateway and SMS gateway for GSM networks. The main use for Kannel is to link HTTP based services to various SMS centers using obscure protocols.Kannel is mainly being developed on Linux systems, and should be fairly easy to port to other Unix-like systems. However, kannel don’t yet support other platforms.
Kannel Installation and Configuration as SMS gateway Server Installation 1 Before installing kannel you will need to install libxml. Download the source and follow the next steps for installation.We can download it from following link.ftp://gd.tuwien.ac.at/pub/libxml/ 2 Unzip it into some directory 3 Cd into directory where libxml is unzipped and then type the following commands 4 Type ./configure 5 Type make 6 Type make install now you have libxml 7 Download latest version of Kannel http://www.kannel.org/download.shtml and Unzip it into some directory or use svn co https://svn.kannel.org/gateway/trunk to download latest version of gateway 8 cd into directory where Kannel is unzipped and then type the following commands 9 Type ./configure –prefix=/usr/local/kannel-1.5.0 –enable-start-stop-daemon –with-mysql 10 Type make 11 Type make install
Now kannel is ready
Next step is to add configuration
Kannel consists of three programs, usually run as daemons: bearerbox, wapbox, and smsbox. They implement the connection to the phone (SMS or UDP), the WAP protocol stack, and the SMS based services, respectively.
We will need only bearerbox and smsbox as we are going to setup it as SMS gateway server. Bearerbox is the main queue and smsbox handles the smscs.
Create a file named kannel.conf and add following configuration
#---------------------------------------------
# CORE
#
# There is only one core group and it sets all basic settings of the bearerbox (and system).
group = core
admin-port = 13000
admin-password = passwd##
smsbox-port = 13010
log-file = "/var/log/kannel/kannel.log"
# Log level is DEBUG
log-level =
access-log = "/var/log/kannel/access.log"
store-type = spool
# Let no SMS be lost as far as possible
store-location = "/var/spool/kannel"
# Acceptable retries for temporary failures in sending SMS
sms-resend-retry = 3
#---------------------------------------------
# SMSBOX SETUP
#
# Smsbox(es) do higher-level SMS handling after they have been received from SMS centers by #bearerbox, or before they are given to bearerbox for delivery
group = smsbox
bearerbox-host = localhost
sendsms-port = 13020
log-file = "/var/log/kannel/smsbox.log"
# Log level is DEBUG
log-level = 0
access-log = "/var/log/kannel/access.log"
#---------------------------------------------
# SEND-SMS USERS
# These users are used when Kannel smsbox sendsms interface is used to send PUSH sms messages
group = sendsms-user
username = tester
password = foobar
concatenation = true
max-messages = 4
#---------------------------------------------
# SMSC CONNECTIONS
# SMSC connections are created in bearerbox and they handle SMSC
# protocol and message relying.
# Example complete configuration
group = smsc
smsc = smpp
smsc-id = PROMO-SERVICE-MESSAGE
allowed-smsc-id = PROMO-SERVICE-MESSAGE
host = X.X.X.X
port = XXXX
transceiver-mode = true
smsc-username = promouser
smsc-password = promopasswd
source-addr-ton = 0
source-addr-npi = 1
dest-addr-ton = 0
dest-addr-npi = 1
system-type = ""
address-range = ""
If you are keen to learn more about this , Refer Here For Sample kannel configuration, check Here
Comments
Anthony
Thanks for this. The send SMS from kannel is not any troublesome. Would you do a guide on receiving SMSs? I have tried everything and but still I cannot received SMS from the same e220 modem that works fine sending from kannel. Thanks again, you guide so far has been very usefull
Sreekanth G S
Start bearerbox first. Smsbox needs to connect to an already running bearerbox instance.
I guess it related to permit_params I am trying this
permit_params :name, :othermodel_ids
but still not working, have you another idea??