Just a quick post on how to block eCheque payments. These are payments that take up to seven days to process and be approved. The site I am currently working on is in no position to reserve services for such a long period of time, so the request has been made to block non-instant payment methods.
In the sandbox environment, you just need to do the following:
Login to your applications PayPal account at sandbox.paypal.com
Press the My Account tab
Select profile (just underneath my account)
Under selling preferences, click Payment Receiving Preferences
Under Block the following payments, check ‘Payments by eCheque on your website. Note: You may not block echeque payments on eBay’
The credit card statement name can also be set here. Let me know if you have any trouble.
I was going through my development logs today and noticed that the following line was appearing everywhere:
WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
While nothing appeared to be wrong, it made the logs a lot harder to read. A stackoverflow post indicates that this is a webrick issue that can be avoided by switching to thin. This is also the recommended option for heroku. In order to use thin, you simply need to add it to your Gemfile:
chris@chris-VirtualBox:~/calendar$ bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..
Using rake (10.0.2)
Using i18n (0.6.1)
Using multi_json (1.4.0)
Using activesupport (3.2.9)
Using builder (3.0.4)
Using activemodel (3.2.9)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.1)
Using rack-cache (1.2)
Using rack-test (0.6.2)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.2.2)
Using actionpack (3.2.9)
Using mime-types (1.19)
Using polyglot (0.3.3)
Using treetop (1.4.12)
Using mail (2.4.4)
Using actionmailer (3.2.9)
Using arel (3.0.2)
Using tzinfo (0.3.35)
Using activerecord (3.2.9)
Using activeresource (3.2.9)
Using bcrypt-ruby (3.0.1)
Using bundler (1.2.3)
Using coffee-script-source (1.4.0)
Using execjs (1.4.0)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.2)
Using json (1.7.5)
Using rdoc (3.12)
Using thor (0.16.0)
Using railties (3.2.9)
Using coffee-rails (3.2.2)
Installing daemons (1.1.9)
Installing eventmachine (1.0.0) with native extensions
Using jquery-rails (2.1.4)
Using libv8 (3.3.10.4)
Using pg (0.14.1)
Using rails (3.2.9)
Using sass (3.2.3)
Using sass-rails (3.2.5)
Using therubyracer (0.10.2)
Installing thin (1.5.0) with native extensions
Using uglifier (1.3.0)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
And finally start thin:
chris@chris-VirtualBox:~/calendar$ rails s thin
=> Booting Thin
=> Rails 3.2.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
Ran into a bit of a problem with FullCalendar today after setting up a JSON feed. My events were only appearing in the month view. This StackOverflow post explains that this is due to the fact that the allDay property wasn’t set.
I ran into the following error while attempting to create a new model called calendar today:
chris@chris-VirtualBox:~/calendar$ rails g model calendar
invoke active_record
The name 'Calendar' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.
It turns out that this was due to the fact that my application was also called Calendar. In order to get around this I decided to rename the application. This required a little bit of searching and thanks to this Stackoverflow post I found references in the following files:
– config/application.rb
– config/environment.rb
– config/environments/development.rb
– config/environments/production.rb
– config/environments/test.rb
– config/initializers/secret_token.rb
– config/initializers/session_store.rb
– config/mongoid.yml (if using Mongoid)
– config/routes.rb
– config.ru
– Rakefile
– app/views/layouts/application.html.erb, in title tag
– initializers/secret_token.rb
– initializers/session_store.rb
Let me know if you find any more spots that I’ve missed!
I’ve been mucking around with FullCalendar recently and decided to share one of the prototypes I’ve ended up with. It basically lets the user change the events without having to do a postback. A user simply has to click the event, type in the changes and hit update.
I’ve posted the code below, however there’s also a zip which is a little easier to manage. Note that you’ll probably want to clean it up a little if you plan to use it in production. The following libraries and plugins are also used:
– jQuery
– jQuery UI
– jQuery FullCalendar
– jQuery miniColors
What it Looks Like:
Full Calendar Example with Client Side Edits
How to Use It:
It’s all pretty straight forward, but just in case any one runs into issues there are two parts to this example. First, you generate an event template. You can then drag and drop this template onto the calendar as many times as you want.
The second part allows you to edit existing events without posting back to the server. To do this, simply click an event and then make the necessary adjustments using the top panel on the right. Once you’re done, just press update event.
The example uses the standard title property, but also includes a few others: descriptions, price, available. You can change/remove these to suit your needs, just remember to pull them out of the JavaScript as well.
Just a site that I came across today that was pretty useful for JSON: http://jsonlint.com/
I’ve been working with jQuery FullCalendar and needed some sample data. It has the option to use a JSON feed but mine wasn’t working for some reason. JSONLint allowed me to both format and validate it.
Let me know if you come across any other useful formatters/validators.
Thanks to this stackoverflow post I realised that the data wasn’t being serialised because I’d disabled most of the fields beforehand. This was done in order to prevent the user from changing the values. To get around this I simply had to serialise the data BEFORE disabling anything.
//Post via ajax
$.ajax({
type: 'POST',
url: 'uploads/add',
data: $(form).serialize(),
success: function(data, text_status, oHTTP){
handle_form_response(data, text_status, oHTTP, $(form).data('file_id'))
},
error: function(){
//Hide loader etc
set_form_loading(false);
//Unspecified error
alert('An error has occurred.');
},
dataType: 'json'
});
//Display loader and disable forms - DO THIS AFTER SERIALISING
disable_form_fields(true);
I ran into a bit of trouble today trying to get datetimepicker to work within bootstrap tabs. The dialog appeared however none of the buttons seemed to work. The fields also remained unpopulated.
It turned out the the issue was caused by the fact that I’d used jquery’s clone function to duplicate the tabs without reassigning field ids. This meant that there were multiple fields with the same id, confusing datetimepicker.
The solution I used was to dynamically assign all of the ids as each tab was displayed:
/* Bind tab change events: this has been done so that there is less js overhead */
function bind_tab_change_events(){
//Bind change event
$('.nav-tabs').bind('show', function(e){
//Create vars
var selected_file_id = $(e.target).data('file_id');
//Initialisations
initialise_time_pickers('#file_' + selected_file_id + ' .timepicker', selected_file_id);
})
}
/* Initalise timepickers */
function initialise_time_pickers(selector, unique_id){
//Loop through each bound element
$.each($(selector), function(index, value){
//Set id - datepicker won't work without unique ids
$(value).attr('id', $(value).attr('id') + '_' + unique_id);
//Initialise datepicker
$(value).datetimepicker();
});
}
UPDATE:
It looks like quite a few people hitting this post are looking for a bootstrap specific alternative, Sebastien has provided a link to one in the comments below: Bootstrap DatetimePicker.
Ran into the following error while I was mucking around with CakePHP today:
preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash
The error seemed a little weird as I wasn’t using any regex. It turned out that it was because of my custom validation methods. I had marked them as private instead of public. A bit of an ambiguous error message so hopefully this will be able to help some of you out!