Friday, April 10, 2009

Error: "ActionController::InvalidAuthenticityToken"

Other resources have documented the details of why the error occurs. Rails is preventing a Cross-Site Request Forgery (CSFR). The resources were a little out of sync with my experience. Suspect the difference results from my environment configured with later SW versions.

Resources
Environment
  • jruby -v : jruby 1.2.0 (ruby 1.8.6 patchlevel 287) (2009-03-16 rev 9419) [x86-java]
  • jruby -S rails -v : Rails 2.3.2
Edit the file app/controllers/application_controller.rb and remove the comment character from the line beginning with "protect_from_forgery :secret => ".

Notes
  • The file name is application_controller.rb, not application.rb, as mentioned in other resources.
  • Added protect_from_forgery :only => [:create, :update, :destroy] to the application_controller.rb file.
I am new to RoR. Misperceptions may be showing through on this topic?

Thursday, April 2, 2009

Jruby on XP functioning. Good progress.

Seems the required gems are installed. See dbc-adapter, jdbcmysql-adapter, and jdbcmysql are all listed.
E:\InstantRails\rails_apps\depot>jruby -S gem list --local

*** LOCAL GEMS ***

actionmailer (2.3.2, 2.0.2)
actionpack (2.3.2, 2.0.2)
activerecord (2.3.2, 2.0.2)
activerecord-jdbc-adapter (0.9.1)
activerecord-jdbcmysql-adapter (0.9.1)
activeresource (2.3.2, 2.0.2)
activesupport (2.3.2, 2.0.2)
jdbc-mysql (5.0.4)
rails (2.3.2, 2.0.2)
rake (0.8.4)
rspec (1.2.0)
sources (0.0.1)
Excellent! jruby -S rake db:migrate now creates the tables in MySQL. Progress, at long last.

Enjoying success with:
  • jruby script/generate scaffold product title: string description: text image_url:string
  • jruby script/server
  • The basic CRUD (Create, Read, Update, Delete) functionality works
Ahhhhhhhhhhhhhhhhh. Very nice, finally! Appears I now have a functioning ruby. Can now concentrate on web development issues. Sweet.

Wednesday, April 1, 2009

Jruby on XP


Visit the Jruby site. Follow those directions. http://wiki.jruby.org/wiki/Getting_Started
Download a copy of the Jruby distribution, a .zip, for XP from that site. Version 1.2.0, which is ruby 1.8.6 patchlevel 287. Extract that archive into a directory, e:\jruby-1.2.0.
  • Add e:\jruby-1.2.0\bin to the %PATH% variable.
  • Add %JAVA_HOME% variable and set to c:\Program Files\Gava\jre1.6.0_07
Try to run jruby script\server. An error message: Please 'gem install -v2.0.2 rails'. Success. All the action* stuff is installed. All the ri and RDoc stuff reports successful installation. This is good stuff so far.

Try jruby script\server again. Failed because it could not run sqlite3. Fair enough. The app was built with MySQL. Let's gem install mysql.
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
Rummaging around searching for solutions ... perhaps the MySQL connection is supported through the Java layer? Others say the JDBC adapter must be used. Let's try,
jruby -S gem install activerecord-jdbcmysql-adapter

Three things seem to have installed successfully, along with the ri and RDoc doc; activerecord-jdbc-adapter-0.9.1, jdbc-mysql-5.0.4, activerecord-jdbcmysql-adapter-0.9.1

Enough for today. More tomorrow.

InstantRails - Fail

Guess InstantRails is also not a solution.

One popup window shows :
Unknown(): (null): Unable to initialize module.
Module compiled with module API=20060613, debug=0, thread-safety=1
PHP compiled with module API=20020429, debug=0, thread-safety=1
These options need to match
Built a trivial rails app to test the installation. Built 2 pages, each linked back to the other. Silly simple stuff. All appears to work.

Add a simple migration. Just a couple of fields in a single table.
ruby script/generate scaffold product title:string description:text
Good. That went well. Let's use rake to build a table.
rake db:migrate
Failure, again. Segmentation fault.
/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:203 [BUG] Segmentation fault
ruby 1.8.6 (2007-09-24) [i386-mswin32]

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Wow, getting a functional rails environment on XP is a real bitch!

Next thought ... Netbeans includes Jruby, and a nice IDE. See if it offers an avenue to success.

To be continued ...