This has caused me 3-4 hours of time wasting and it is so bloody simple! I can't believe after googling for so many hours that I could not find something that could solve this problem for me.
If you've came across an error #1452 when trying to add a foreign key and you have existing entries in the table, you need to make sure there are valid values in all entries in the foreign key column before creating a foreign key.
So what I did was do a zero fill on the foreign key column. Sweet I thought. This should fix it. After trying to create the foreign key again, I get an error #1216. Turns out that the values in the foreign key column must be valid (i.e. correspond to a valid id to referenced table) and the zero fill obviously didn't help because I dont have any id with 0.
Once you've entered valid values in, the foreign key creation should work! Make sure that the column in the referenced table is a primary key or an index and foreign key column is an index before proceeding.
Thursday, 18 October 2007
Foreign Key in MySQL Error #1452 and #1216
Wednesday, 17 October 2007
Progress Update
Have been working on budgeting functionalities this past couple of weeks. Seems like I've managed to get these things working though it may require further testing.
- Transactions - Add/Edit/Delete (admin, member, guest)
- Jobs - Add/Edit/Delete (admin) [job description might still need some work]
- Projects - Add (all) [need to do edit and delete]
- Members - Add/Delete (admin) [need to do permission editing]
Friday, 12 October 2007
Tuesday, 2 October 2007
ImageMagick / RMagick / Gruff - Installation
Installing RMagick is known to be a complex procedure, especially with an InstantRails environment. The first step is to download the RMagick-win32 package from the following location:
http://rubyforge.org/frs/download.php/24863/RMagick-1.14.1_IM-6.3.0-7-Q8-2.zip
Very nice...
The standard procedure, found in the file called README.html in the above archive, should generally be followed. However, the following modifications will need to be inserted for the installation to work with the InstantRails environment and to obtain the functionality required for FoR:
--------------------------------------
set HTTP_PROXY=http://proxy:port #(check for proxy and port in firefox)
gem update --system -y
gem install rmagick --local
gem install gruff -y
add to environment.rb -> require 'rubygems'
#also add "require 'RMagick'" to necessary controllers
#also add "require 'gruff'" in the controllers which are going to create gruff graphs
--------------------------------------
The following links may also be of use during installation:
http://docs.rubygems.org/read/chapter/3#page70
http://nubyonrails.com/pages/gruff
http://geoffreygrosenbach.com/projects/show/5
Monday, 17 September 2007
Let's play with Sortables
Ok, this seriously took me such a long time to figure out. I'm trying to create sortable menu customisation, like the one you see in your personalised Google homepage. The tutorial I followed was the one provided by scrtip.aculo.us.
First of all, you have to create a block container. In this case I used a div element. Its child div elements are the ones that I want to move around, and sort according to the user's preference.
For example,
<div id="container">
<div id="left" style="float:left;width:50%;background:red;">Left Div</div>
<div id="right" style="float:right;width:50%;background:green;">Right Div</div>
</div>
This displays the two child divs next to each other, like a table format but without using table tags. Using Rails helper,
<%= sortable_element "content_container", :tag => "DIV", :constraint => false %>
This specifies that the sortable list is the container which has lists in it. By default, the li tag is treated as the list, that is why you have to specify :tag => "DIV". The :constraint => false all allows free movement when dragging (default is vertical).
After doing so, you'd think that it should all work perfectly. Not really to be exact. This bug caused me lots of trouble to figure out as I had no idea why it wasn't working. You would be able to drag the elements, but it just would not sort.
Fiddling around for some time, I came across what the problem was. When the right div is sorted to the left, the css tells it to float right meaning the css is preventing the sorting from happening. In other words, when it is in the left position, it wants to float right. Obviously this is incorrect.
So I changed the right div to float left, which will still keep the alignment correct. This solved the problem pretty much. However, you are only able to sort the elements from right to left, and not the other way around. I still can't figured out why and how to fix this.
Try it out here,
[edit date="18/09/07"]
Hmm, a bloody weird discovery. Left to right actually works! It isn't as responsive as right to left though. Left to right is harder to sort, but if you position it kinda properly, it works.
Weird.
[/edit]
Posted by
Danny Ng
at
10:35 pm
0
comments
Labels: css, dragdrop, effects, javascript, ruby helper, script.aculo.us, sortable
Rendering Global Partials
Just a quick note to point out. If you want to render a partial thats available globally (by default its local), all you have to do is create a folder in ..\app\views.
Assuming we created a folder called shared and a partial called _menu.rhtml, you can then access it by doing,
render :partial => "shared/menu"
Simple.
Dealing with JavaScript Object Notation (JSON)
Ruby on Rails provides an easy way to render JavaScript Object Notation (JSON) without actually having to deal with itty gritty details of forming the object literal.
# Controller
render :json => { :name => "Danny", :title => "Mr" }.to_json
produces
{ name: 'Danny', title: 'Mr' }
Once you have done so, you can create an object in javascript by running
var person = eval("(" + request.responseText) + ")");
You can then access the attributes by going person.name and person.title which returns "Danny" and "Mr", as expected.