Posted in rails on November 19th, 2011 by paul – Be the first to comment
I discovered that my ‘destroy’ links in a rails 3.1 app where routing to the show action of the relevant controller.
It seemed that the javascript was not firing for some reason.
I had the jquery-rails gem in my Gemfile ok but jquery was not being loaded.
Eventually I worked out a solution (there may be better solutions…)
In my application.html.erb layout file my javascript include was :
<%= javascript_include_tag :defaults %>
which meant that I was trying to load a defaults.js file which didn’t exist.
I changed this to
<%= javascript_include_tag :application %>
and suddenly everything is working, i.e. application.js is being loaded and destroy links are now doing what one would expect.
Simples.
Posted in linux, ruby on July 28th, 2011 by paul – Be the first to comment
I recently had to get a merb site up and running on a ubunto 9.10 vps.
I haven’t worked with merb before so there was something of a learning curve, but not too much.
Anyway, the site uses image science for image manipulation.
Once I had everything installed , trying to run merb in the application root gave me the following error:
/usr/bin/ld: cannot find -lstdc++
From the trace this seemed to be related to ruby inline.
Anyway, short version is that once I installed libstdc++6-4.4-dev merb was able to start up ok.
I hope this helps someone else out there.
Posted in cpanel on July 26th, 2011 by paul – Comments Off
A client asked me to install ssl certificates for two subdomains of one of their client’s sites.
As they were restricted to one IP address I went down the wildcard ssl route.
There is a lot of conflicting information out there about how to go about installing a wildcard ssl certificate in cpanel. Some sources say it’s not possible. Others say it is but you have to edit lots of cpanel config files by hand (which is never a nice thing to have to do).
In the end it was relatively straight forward.
I generated a key and csr by hand on the server by the usual methods. i.e. openssl genrsa etc etc.
The key here was specifying the domain as *.domain.com .
I then bought the wildcard ssl certificate.
Finally, I logged in to the client’s cpanel account, went in to the ssl/tls manage but, and then the Activate SSL on your website part.
I selected domain.com from the dropdown, pasted the contents of the crt file and the key I generated earlier, and clicked the Install Certificate.
And much to my surprise it worked.
ymmv, ianal, bbqrofl
Posted in rails, ruby on July 7th, 2011 by paul – Be the first to comment
Recently while working on an old 2.3.x rails app I found I was having problems with the version of rubygems installed. In the end I had to install rubygems version 1.6.2 to get a rails app version 2.3.11 to boot.
The command to install this specific version of gem is
gem update –system 1.6.2
Posted in Uncategorized on July 7th, 2011 by paul – Be the first to comment
While deploying to a new server recently I found myself confronted with the following error message:
uninitialized constant Rake::DSL
It would seem that this error is related to the version of rake installed on the server.
I installed an older version and removed the latest version.
gem install rake –version=0.8.7
gem uninstall rake –version=0.9.2
Everything is working ok now.
Hint found here.
Posted in javascript, memotoself on September 27th, 2010 by paul – Be the first to comment
This is probably really obvious, but I’m putting it here for my own reference.
So I have a javascript function that builds a string and returns it to the caller.
However, I had this problem where the returned string always started with undefined .
It didn’t take me too long to work out what was wrong here; namely that I didn’t initialise the variable before I started appended to it, so it always started with undefined.
So something like:
var return_string;
return_string += "Some stuff";
Wrong!
var return_string = "";
return_string += "Some stuff";
Right!
Obvious really…
Posted in linux, memotoself on March 23rd, 2010 by paul – Be the first to comment
find .* -mtime +14 -exec rm {} \;
Posted in javascript, jquery, rails on February 20th, 2010 by paul – Be the first to comment
The following is one way to handle json responses from a rails application.
So, I have a ajax request in a script in my page. In this example I am using the jquery poll plugin to poll the status of a file import.
$("#<%=import.id%>").poll({
url: "/mis_imports/import_state/<%=import.id%>",
interval: 3000,
type: "GET",
success: function(data){
var return_data = eval('(' + data + ')');
$("#<%=import.id%>").attr("class","mis_import_state_"+return_data.state);
$("#<%=import.id%>_message").html(""+return_data.status+"");
$("#<%=import.id%>_timestamp").html(""+return_data.timestamp+"");
if (return_data.state == 1){
$(this).stop();
}
}
});
And on the server, my rails action method looks like this:
def import_state
import = MisImport.find(params[:id])
render :text => {:state => import.state,:status => import.message,:timestamp => Time.now.strftime("%d:%b:%Y %H:%M:%S")}.to_json
end
The key part to this working is line 6 of the javascript listing, where one ‘evals’ the data returned from the server.
This effectively rehydrates the data structure into a usable javascript object, and that’s the bit I keep forgetting!
There are probably smarter ways of doing this; I know there is a jQuery.getJSON() function, but in this case I couldn’t work out how to use that with jquery poll. Again, probably very simple…
Posted in memotoself, symfony on January 19th, 2010 by paul – Be the first to comment
I wanted to use the preInsert() method to do some calculations on a model class before it was saved. But I encountered the error:
Strict Standards: Declaration of Blah::preInsert() should be compatible with that of Doctrine_Record::preInsert() in /PATH/lib/model/doctrine/Klass.class.php on line 14
The code I had in my class file looked something like this:
public function preInsert(Doctrine_Event $event)
{
$this->calculate_status();
}
This seemed correct, but I was getting this strict error.
Anyway, short story shorter, I removed the Doctrine_Event (type hint?) from my method signature and the warning went away.
New code looks like this:
public function preInsert($event)
{
$this->calculate_status();
}
Posted in memotoself, symfony on January 9th, 2010 by paul – 3 Comments
I’ve started using the Symfony PHP framework for my php projects, and while the learning curve has been steeper than I would have liked, I’m getting there.
Anyway, one of the problems I’ve had a few times over the current project is the error
“couldn’t get last insert identifier”
So far, the problem has been down to the object I have been trying to create didn’t have it’s id field set to autoincrement. Or perhaps more accurately, setting that model’s id field to autoincrement has sorted the problem so far.
Hopefully once I get the hang of the schema file and the (what appears to be) the slightly different syntax for migrations, all my models should have autoincrement id fields and this shouldn’t be a problem anymore.