How to implement data ordering and importing/exporting?
Here's the situation in the context of shovell application
Let's say we need to add new stories. To make it more effective we could use importing.
zip The story teller, http://www.zip.com/story_teller/
zip The fantastic adventure, http://www.zip.com/fantastic_adventure/
zip Summer holidays, http://www.zip.com/summer_holidays/
zip Space travel, http://www.zip.com/space_travel/
The reverse would be nice too (exporting).
Next: it would be good to sort the data.
Much like fetch_stories method in stories_controller.rb. How to display stories that start with "zip". I know how I would do that in PHP. I would make SQL statement "select * from stories where name like 'zip%'". And of course HTML select tag to select stories where the link is for a particular domain like "http://www.zip" (this would be the sort by unique value filter).
Then the other: ordering. A link over columns to order data ascending or descending. Should the direction be stored in session hash?
It seems like a basic thing but it's not. I don't know how to operate forms in rails well enough as I do in PHP.
Thanks in advance!
Absolutely. Instant Rails is more trouble than it is worth. It is very easy to install the elements separately, and far more reliable.
I'm not sure what you mean by "importing" and "exporting." Could explain that a little more fully and then maybe I can help.
As far as sorting stories that could be fairly easy depending on how you want to do it. There is a gem called Searchlogic that is excellent for searching and includes functions for sorting as well. http://github.com/binarylogic/searchlogic
Think of the data input mentioned in the starting chapters of the book.
Open irb console, type information manually like:
Then a form was introduced to add a story. But you add each story separately.
So, how to expand this functionality to add many stories.
What I have in mind is a link to populate database with test data to add a bunch of stories just to test the functionality.
Sure I could use a database client but I haven't dealt with sqlite3 DBMS. I use SQLyog for MySQL.
Thanks for the information, very useful, if you have more information please tell us.
If you are wanting to put data in simply to test it, I would recommend creating a migration to populate the test data. I would also recommend getting comfortable with fixtures, unit tests, and the functional tests that are part of the Rails core since these will help you find bugs much more efficiently than populating a db and clicking on everything to see if it works.
Tests need to be re-written if changes occur in the application. I am used to manual tests. When I went along the simply rails 2 2nd edition book tests were the part that I failed at. I didn't use the code archive and typed it from the book. I did make some spelling mistakes but I couldn't get the tests to work so I gave up because the rest of shovell was functioning like expected.
Maybe in time but for now I would be grateful if you could demonstrate a sample of how that migration file would look. I need test data for demonstration purpouses so that I can show to the audience an empty database, then not to waste time load some test data and demonstrate again that this data is now available.
If you want to "seed" your database, Rails provides a way to do it. http://railscasts.com/episodes/179-seed-data Not sure if you are familiar but the Railscasts are excellent for learning about Rails, there may even be something about adding multiple records at once.
It would be even better if it worked
Don't know how to build task 'db:seed'
(See full trace by running task with --trace)
What version of rails are you running? Anything lower than 2.3.4 doesn't have the "seed" function.
puts "rails seed database"
Hmmm...that is weird. I just tried it on a fresh 2.3.5 install on Instant Rails and it worked.
Perhaps your version of rake is off? You can check what version you have by running gem list
and if rake needs to be updated you can run: gem update rake
Let me thank you for the help so far. I appreciate your cooperation.
Here's the output of gem list and gem update rake
*** LOCAL GEMS ***
actionmailer (2.3.5, 2.0.2)
actionpack (2.3.5, 2.0.2)
activerecord (2.3.5, 2.0.2)
activeresource (2.3.5, 2.0.2)
activesupport (2.3.5, 2.0.2)
capistrano (2.5.10, 2.1.0)
fxri (0.3.7, 0.3.6)
highline (1.5.1, 1.4.0)
hpricot (0.8.2, 0.6)
log4r (1.1.2, 1.0.5)
mongrel (1.1.5, 1.1.2)
mysql (2.8.1, 2.7.3)
net-sftp (2.0.4, 1.1.0)
net-ssh (2.0.16, 1.1.2)
rails (2.3.5, 2.0.2)
rake (0.8.7, 0.8.1, 0.8.0, 0.7.3)
rubygems-update (1.3.6, 1.3.5, 1.0.1)
sqlite3-ruby (1.2.5, 1.2.1)
C:\\InstantRails\\rails_apps>gem update rake
Updating installed gems
Nothing to update
Maybe all of this has something to do with rails enforcing the use of version 2.0.2. Some step in the book. I don't know.
Ahhh! That would be the problem! In your environment.rb file you should have a line that looks like this:
RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
This is telling the system to use Rails 2.0.2. (which did not have the db:seed feature) You simply need to change it to this:
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
Also, something to keep in mind is that if you run gem cleanup, it will remove old versions of gems that you have on your system. Run it like this: gem cleanup -d For a "dry run" to see exactly what it is going to remove and then run gem cleanup if you want to actually remove old gems.
Still no luck. Maybe I should just re-install everything but this time without instant rails. Ruby, then RubyGems and so on. It would be nice if there was a way to get rails working with wAMP.
=> Booting Mongrel
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be
removed on or after August 2010. Use #requirement
n `send': undefined method `cache_template_extensions=' for ActionView::Base:Cla
... 6 levels...