Monday, November 19, 2007

InstantRails MySQL Pending...

Click the MySQL button. Kill it. It will automatically restart.

Friday, November 16, 2007

7 Steps To A Ruby On Rails Application

1.Install Ruby and Rails

  • I'm using Ubuntu and did this with the Synaptic package manager.
  • I'm also going to try InstantRails, http://rubyforge.org/frs/?group_id=904


2. Generate the application's framework.

$ cd <work_root>
$ rails MyApp
$ cd MyApp


3. Create a Controller.
$ script/generate controller MyControl
NOTE: With Windows and Instant Rails, preface the script commands with ruby.

4. Edit the Controller. Add an action, some_action
$ gedit app/controllers/my_control_controller.rb

class MyControlController < ApplicationController
def some_action
@time = Time.now
end
end


5. Add the view associated with the action.
$ gedit app/views/my_control/some_action.rhtml

<html>
<head>
<title>Action!</title>
</head>
<body>
<ul>
<li>It is now <%= @time -%>
</ul>
<body>
</html>

6. Start the server.
$ script/server
NOTE: With Windows and Instant Rails, preface the script commands with ruby.

7. View the result in a browser.
http://localhost:3000/my_control/some_action


Note: (From Agile Web Development with Rails by Dave Thomas and David Heinemeier Hansson)

In Ruby, the convention is to have variable names where the letters are all lowercase and words are separated by underscores. Classes and modules are named differently:
there are no underscores, and each word in the phrase (including the first) is
capitalized.

Rails controllers have additional naming conventions. If our application has a store controller, then the following happens.
  • Rails assumes the class is called StoreController and that it’s in a file named store_controller.rb in the app/controllers directory.
  • •It also assumes there’s a helper module named StoreHelper in the file store_helper.rb located in the app/helpers directory.
  • It will look for view templates for this controller in the app/views/store directory.
  • It will by default take the output of these views and wrap them in the layout template contained in the file store.rhtml or store.rxml in the directory app/views/layouts.

Tuesday, November 13, 2007

Ruby on Rails - changing the default IP, server startup

How to get informative error pages:
$ script/server --environment=development

How to get informative error pages and access from a different box:
$ script/server --binding=<your IP goes here> --environment=development

The default, if you start with script/server you get the following:
$ script/server --binding=127.0.0.1 --environment=production

Friday, November 9, 2007

msql man page missing a ;

$ man mysql
gives the following:

Beginning with MySQL 5.0.40, the XML output also uses an XML namespace, as shown here:

shell> mysql --xml -uroot -e "SHOW VARIABLES LIKE ’version%’"



The mysql --xml -uroot -e "SHOW VARIABLES LIKE ’version%’" fails.
Use the following:
mysql --xml -p -uroot -e "SHOW VARIABLES LIKE 'version%';"

Wednesday, November 7, 2007

Serving JSP from Tomcat 5.5 on Ubuntu 7.10

Serving JSP from Tomcat 5.5 on Ubuntu 7.10

- Tomcat installed on Ubuntu 7.10, used Synaptic package manager.
- /etc/init.d/tomcat5.5 start
- /etc/init.d/tomcat5.5 stop
- /usr/share/tomcat5.5 is where tomcat lives.
- /usr/share/tomcat5.5-webapps is where the webapps live.


Create /usr/share/tomcat5.5-webapps/ROOT/test.jsp with the following contents:

<html>
<body>
<%java.util.Date d = new java.util.Date();%>

Todays date is <%= d.getDate()%> and this jsp page worked!

</body>
</html>

---
Subnote: To get the less than and greater than signs for the tags I use &lt; and &gt; There is a nice page that will do the conversion for you at : http://www.stanford.edu/~bsuter/js/convert.html

Sunday, November 4, 2007

Right-Brain, Left-Brain Which are you?

Brain Lateralization Test Results
Right Brain (34%) The right hemisphere is the visual, figurative, artistic, and intuitive side of the brain.
Left Brain (60%) The left hemisphere is the logical, articulate, assertive, and practical side of the brain
Are You Right or Left Brained?
personality tests by similarminds.com

Friday, November 2, 2007

Tomcat and PHP on Linux

To date, the way I got it working is to run the PHP code as a CGI program. More to come. Got the following from Well House Consultants "Running CGI scripts in Apache Tomcat

----

CGI scripts are usually run under an httpd web server, but if you've only got a few CGIs and a lot of .jsp-s and servlets, you may want to run them under Tomcat instead. It can be done, but there are some configuration things to do first!

SAMPLE CGI SCRIPT

Here's a sample cgi script that you might want to install on your Tomcat server:

#!/usr/bin/perl

print "Content-type: text/html\n\n";

$now = localtime();
print "<h1>It is $now</h1>";

The file should be:
 * In a directory called WEB-INF/cgi in the webapp
 * have an extension .cgi
 * be set to be executable (chmod a+x xxxxxx)

If you want to vary the location and extension, you can do so by altering the text configuration quoted below.

CONFIGURING TOMCAT TO SUPPORT CGI

Although CGI support is shipped with the standard Tomcat load, the vital information that you'll need is commented out in the web.xml file and you need to uncomment the following to add in the support:

    <servlet>
        <servlet-name>cgi</servlet-name>
        <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
        <init-param>
          <param-name>debug</param-name>
          <param-value>6</param-value>
        </init-param>
        <init-param>
          <param-name>cgiPathPrefix</param-name>
          <param-value>WEB-INF/cgi</param-value>
        </init-param>
         <load-on-startup>5</load-on-startup>
    </servlet>

and also you need to map appropriate URLs on to that support:

    <servlet-mapping>
        <servlet-name>cgi</servlet-name>
        <url-pattern>*.cgi</url-pattern>
    </servlet-mapping>

There's one further change to make - the CGI API is provided in a .jar file that you need to rename in the /usr/local/tomcat/server/lib (or similarly named) directory:

mv servlets-cgi.renametojar servlets-cgi.jar