I'm sorry if these are very simple questions, I just haven't been able
to find useful answers for my problems.
I've been programming in Ruby for a couple years, and recently started
with Rails (having felt most of Ruby seems to be in that direction,
these days), so I have a reasonable amount of knowledge in ruby
scripting but know very little about how to get Rails to do my bidding.
So far I've followed a couple "create a blog" tutorials, and have gained
a few steps in the right direction, but I still have a few issues.
The server that hosts my applications only runs Rails version 2.3.14, so
please try to keep any code/suggestions compatible.
What I would like, in my project, is for there to be two input fields:
"subject" and "keywords". One subject can have multiple (limited; maybe
up to 7? doesn't really matter) keywords, which will be found in the
"keywords" field and delimited by commas.
Obviously in ruby it would be a simple keywords.split(',').
Each keyword (after being split) will also have a few attributes which
are entirely ruby-defined. Suppose they're length and number of vowels.
Basically things that I want stored in the database which aren't
strictly input by a user.
As far as I know, the first steps in Rails to set up my database would
be to use the following commands:
ruby script/generate scaffold search subject:string words:text
ruby script/generate scaffold keyword word:string length:integer
(and then I would add the "has_many" to search and "belongs_to" to
And basically all the app needs to do, after, is display all of the
previous subject words, and for each post each keyword and its
attributes (length, etc.).
But every tutorial I can find tends to deal with inserting user input to
the database, rather than inserting the output of Ruby scripts.
That looks like it should set things up for me, but the real questions
I'm facing are:
1) How do I add a variable number of things (keywords) to the database
from within Rails?
2) How do I store entirely-ruby-determined attributes like a string's