Archive

Posts Tagged ‘Ruby’

No association found for name `products'. Has it been defined yet?

May 24th, 2010

Working on a project, I had to make some changes to the associations – where Product_Lines had many Products to Product_Lines has one Product.  (The reason behind this is a whole other story.)

This is the error I got:

No association found for name `products’. Has it been defined yet?

I had changed the Product_Lines model to has_one Product.  But, I had over looked the accepts_nested_attributes_for line.  I changed :products to :product and it fixed it.

Andrew Development ,

RubyMine & Git

April 8th, 2010

In order to get Git working in RubyMine, you’ll need to go into preferences and setup the path for the executable.

Preferences > VCSs > Git

Path to git executable: /usr/local/git/bin/git   (for OSx)

Andrew Development , , , ,

Rails: how to change the header (title) for the validation message

March 31st, 2010

The request was simple – how do you change the header (or title) for a validation message.  Using nested resources, I ended up with a weird message:

3 errors prohibited this page[contact attributes] from being  saved

Not very user friendly.   So, I hit Google, blogs and IRC.  So, here the solution I discovered.

<%= error_messages_for ‘c’, :header_message => “Please correct the errors below:”%>

Since this was part of a fields_for block,  I had to add this to my controller method:

@c = @section.contact

Andrew Development , , , ,

Jumping into Ruby on Rails – Part 3

February 5th, 2010

Well, I’ve been working on learning Ruby on Rails for several months now.  The past couple of months, I’ve focused more on my studies and I’m finally feeling comfortable with it.

I thought it would be best to share what I think would be the best way to approach learning Ruby on Rails based on all of my experiences.  So, here are my suggestions

1. Learn Ruby on Rails on Linux or a Mac.

Why?  It’s just easier.  An example to this is getting the MySQL gem installed on Windows – after hours of trying to figure this out, I finally gave up and started to use Linux.  You will spend hours trying to get something to work under Windows and to me that is just wasted time.  And I tried all different kinds of approaches – Cygwin, Instant Rails, etc.

2. Learn Ruby

Here are some suggestion:

Programming Ruby 1.9: The Pragmatic Programmers’ Guide (Facets of Ruby)

Free (if you buy a book) class.

Also, most Ruby on Rails books will give you a sufficient overview to the Ruby language to get started.

3. Expect gaps of informaton

This was a *huge* problem for me.  I started working my way through the Agile Web Development with Rails book, that presents itself as a book  from a beginner to an expert.  Well, I discovered that the book *expects* you know the nuances of Rails.

I’ve looked at a good number of books and found this one to be a great one to start with:

Ruby on Rails Bible

Note:  While the book was published in 2008, it covers Rails 1.2 – which was current in 2005.  So the book is a *bit* dated.  However, it does present itself with knowledge about Rails that other books leave out.  Also, as a co-worker pointed out, the web site for the book is – uh, well – broken.

So, specifically, as most Railists know – RoR is convention over configuration – and what I find missing in most books is a good explanation of the conventions.

4. Watch some screen casts:

Free

Railcasts

TeachMeToCode.com ** check out the Flitter tutorial

Paid

PeepCode ** $149 a year – has tutorials on Ruby, Rails, and much more!

Well, that’s my advice.  Let me know if you have any suggestions!

Andrew Development , , ,

Error installing libxml-ruby

February 1st, 2010

So this:

sudo gem install -r libxml-ruby

Gives you this:

ERROR:  Error installing libxml-ruby:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb
checking for socket() in -lsocket… no
checking for gethostbyname() in -lnsl… yes
checking for atan() in -lm… no
checking for atan() in -lm… yes
checking for inflate() in -lz… yes
checking for iconv_open() in -liconv… no
checking for libiconv_open() in -liconv… no
checking for libiconv_open() in -llibiconv… no
checking for iconv_open() in -llibiconv… no
checking for iconv_open() in -lc… yes
checking for xmlParseDoc() in -lxml2… no
checking for xmlParseDoc() in -llibxml2… no
checking for xmlParseDoc() in -lxml2… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=/usr/bin/ruby1.8
–with-iconv-dir
–without-iconv-dir
–with-iconv-include
–without-iconv-include=${iconv-dir}/include
–with-iconv-lib
–without-iconv-lib=${iconv-dir}/lib
–with-zlib-dir
–without-zlib-dir
–with-zlib-include
–without-zlib-include=${zlib-dir}/include
–with-zlib-lib
–without-zlib-lib=${zlib-dir}/lib
–with-socketlib
–without-socketlib
–with-nsllib
–without-nsllib
–with-mlib
–without-mlib
–with-mlib
–without-mlib
–with-zlib
–without-zlib
–with-iconvlib
–without-iconvlib
–with-iconvlib
–without-iconvlib
–with-libiconvlib
–without-libiconvlib
–with-libiconvlib
–without-libiconvlib
–with-clib
–without-clib
–with-xml2-config
–without-xml2-config
–with-xml2-dir
–without-xml2-dir
–with-xml2-include
–without-xml2-include=${xml2-dir}/include
–with-xml2-lib
–without-xml2-lib=${xml2-dir}/lib
–with-xml2lib
–without-xml2lib
–with-libxml2lib
–without-libxml2lib
–with-xml2lib
–without-xml2lib
extconf failure: need libxml2.

Install the library or try one of the following options to extconf.rb:

–with-xml2-config=/path/to/xml2-config
–with-xml2-dir=/path/to/libxml2
–with-xml2-lib=/path/to/libxml2/lib
–with-xml2-include=/path/to/libxml2/include

So, do this:

sudo apt-get install libxml2-dev

And this again:

sudo gem install -r libxml-ruby

Andrew Development , , , , , ,

Rails Newb – how to install will_paginate

January 24th, 2010

One of the frustrating things about Rails is coming up to speed with everyone else.  A very simple task can be difficult, just because you haven’t done a particular task yet.  Well, that’s ok.  That’s what the community is for.  So, I’m sharing those little things here.

This one is how to install will_paginate.  Not so much how to install it – but how to add a new source to the gem sources.

gem sources

do you see http://gemcutter.org?  if so, skip the next command

gem sources -a http://gemcutter.org

sudo gem install will_paginate

Andrew Development , , , , , ,

Setting up MySQL to use less memory

January 20th, 2010

So, you’re on a VPS with 128MB of RAM or doing development on your Linux workstation and you don’t want MySQL to hog all of the memory — here is what you do:

sudo cp /etc/mysql/my.cnf /etc/mysql/my.cnf.backup
sudo cp /usr/share/doc/mysql-server-5.1/examples/my-small.cnf /etc/mysql/my.cnf
sudo /etc/init.d/mysql restart

** verify the version # on the second command line.

Andrew Development , , , , , , ,

map.root :controller => does not work.

January 12th, 2010

I’m working on one of my first apps and I discover that the map.root :controller => does not work.  I verified the controller was spelled correctly, but it kept taking me to the Ruby On Rails intro page.

Solution: delete the index.html out of /public/

Andrew Development , , , ,

Problem installing sqlite3-ruby

January 8th, 2010

Getting the following error message?

desktop:~# gem install sqlite3-ruby
Building native extensions.  This could take a while…
ERROR:  Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb
extconf.rb:1:in `require’: no such file to load — mkmf (LoadError)
from extconf.rb:1

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5/ext/sqlite3_api/gem_make.out

Solution: apt-get install ruby1.8-dev

Andrew Development , ,

The application has failed to start because sqlite.dll was not found.

November 4th, 2009

Ruby on Rails on Windows Vista :: Getting error “The application has failed to start because sqlite.dll was not found.”

Solution:

Copy sqllite3.dll to a directory that is in your %path% variable.

Andrew Ruby on Rails , , , ,