undefined method `to_sym’ for nil:NilClass – Ruby on Rails Migration

While trying to do a migration today I received the following message:

undefined method `to_sym’ for nil:NilClass

#After running a trace (rake db:migrate –trace)
undefined method `to_sym’ for nil:NilClass
/usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/whiny_nil.rb:48:in `method_missing’

This was the migration:

class AddDefaultValuesToFeedbacks  0
    change_column :stores, :rating, :decimal, :precision => 8, :scale => 2, :default => 0
  end
end

Unfortunately this problem also prevented me from performing any other migrations on the table. I attempted deleting all relevant migration files and then re-running them, restarting the server and rolling back to a previous migration – none of which worked.

Eventually I resorted to exporting the dataset, dropping the table via sqlite3 and recreating it. Thankfully this seems to have worked. The only hint I’ve come across that may explain the cause of this problem, other than typos or referring to non-existant columns, is that it can occur if a migration is screwed over before it finishes and fails to rollback properly.

If anyone else has any concrete answers, please let me know in the comments!

Debugging with Exceptions – Ruby on Rails

Ran into a bit of trouble with a model today, after a bit of a google I came across this technique which helped me solve it:

#Raise exception on object.inspect
raise Object.inspect

#Example 1
raise order.inspect

#Example 2
raise [sub_orders.count].inspect

This simply allows you display variable values as an exception. By placing a few of these throughout your troublesome code you can simulate a fully targeted trace.

Submit form_for to Custom Action – Ruby on Rails

Just another quick problem I ran into with rails this afternoon – how to submit a form_for to a custom action. Luckily there’s quite a bit on how to do this in the documentation, my solution ended up as follows:

 url_for(:controller => 'feedbacks', :action => 'leave_seller_feedback') do |f| %>

Just substitute your form_for tag with the one above and put in the relevant details and it should all work fine. Keep in mind that the submit tag doesn’t need to be changed, just the form_for tag.

Setting Default Slider Value – jQuery UI

Had a bit of a muck around with jQuery sliders today, just though I’d post the code I used to set a default value in case anyone else has a use for it:


//Create sliders
$(document).ready(function() {
   $(".slider").slider("option", "value", 100);
});

Just sub whatever you want your default slider value to be in place of the 100. The jQuery documentation is also pretty useful if you’re chasing any more info: jQuery Slider Documentation

Cheers

Copying Text from Notepad++ to Microsoft Word

In the middle of doing up some documentation I realised that the formatting and colors aren’t kept when you copy and paste from Notepad++ to Microsoft Word. Luckily Google was able to help out by showing me default plugin that lets you keep all the syntax highlighting etc.

1: Hightlight any of the text you want copied
2: From the menu select Plugins > NppExport > Copy all formats to clipboard
3: Paste into Microsoft Word
Highlight code
Highlight code
Select NppExport
Select NppExport
Paste in Word
Paste in Word

And that’s it – all done!

How to Edit a Message Catalog Definition – PeopleSoft

Editing a message catalog definition in PeopleSoft is pretty straight forward, simply browse to the following menu path:

PeopleTools > Utilities > Administration > Message Catalog

Enter your message set number into the prompt. Note that if you do not know your message set number you can use the following to find it:

SELECT *
FROM PSMSGCATDEFN
WHERE MESSAGE_SET_NBR = '12345'
      AND MESSAGE_NBR = '12345';
      
SELECT *
FROM PSMSGCATDEFN
WHERE MESSAGE_TEXT LIKE '%what your message is%';

Once you have your message simply edit the text and description appropriately then save!

Error when trying to Edit a SharePoint Document – SharePoint

Ran into the following error when trying to open a word document stored on SharePoint today:

The document could not be opened for editing. A Microsoft SharePoint Foundation compatible application could not be found to edit the document.

Unfortunately this appears to be an issue with Chrome, once I switched to IE it all worked fine.

Uncaught TypeError: Object # has no method ‘toggle’ – jQuery

Ran into a bit of a problem with jQuery today, not entirely sure what the issue was but apparently it did not like me using the .get() function. I received the following error:

//Enable toggling of sub_order display
$(document).ready(function() {
    $('.expanding_header').click(function(){
      $(this).find('.expanding_content').get(0).toggle('slow', function() {
      });
    });
});
Uncaught TypeError: Object # has no method ‘toggle’

By substituting the get function with a :first selector the error does not occur:

$(document).ready(function() {
    $('.expanding_header').click(function(){
      $(this).find('.expanding_content:first').toggle('slow', function() {
      });
    });
});

Flash Notice Appearing Twice – Ruby on Rails

Ran into another flash notice issue, my messages were not disappearing after the first view. My code was as follows:

#Create flash warning
flash[:warning] = ("This product has been replaced: " +new_product.title + "").html_safe

It turns out that all you have to do to fix this issue is the following:

flash.now[:warning] = ("This product has been replaced: " +new_product.title + "").html_safe

This blog gives a brief overview of when to use flash.now[notice] and when to use flash[:notice]. A basic rule of thumb is that if you’re using a redirect, use flash[:notice], if you’re simply rendering a view, use flash.now[:notice].

Sleep Function Within PeopleCode – PeopleSoft

While at work today I discovered that there doesn’t appear to be any built in functionality to allow for a delay to be implemented within PeopleCode. Thankfully there are a couple of roundabout way you can go about doing this:

#1: Works if you are sitting on an Oracle DB

/* The following code creates a 5 second delay using DBMS_LOCK.SLEEP */
&s = 5;
SQLExec("exec DBMS_LOCK.SLEEP(:1)", &s);

#2: Note that this method is not as efficient as DMBS_LOCK.SLEEP()

/* The following code creates a 5 second delay using the java sleep method */
&s = 5;
GetJavaClass("java.lang.Thread").sleep(1000 * &s);