axelsword — 2010-05-11T06:33:39-04:00 — #1
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!
reggieb — 2010-06-04T08:54:05-04:00 — #2
Absolutely. Instant Rails is more trouble than it is worth. It is very easy to install the elements separately, and far more reliable.
scannon — 2010-05-11T08:53:13-04:00 — #3
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
axelsword — 2010-05-11T10:18:09-04:00 — #4
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.
jeffdacosta — 2010-05-11T10:20:19-04:00 — #5
Thanks for the information, very useful, if you have more information please tell us.
kmsolorio — 2010-05-11T15:26:13-04:00 — #6
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.
axelsword — 2010-05-12T04:12:08-04:00 — #7
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.
scannon — 2010-05-12T10:32:34-04:00 — #8
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.
axelsword — 2010-05-13T05:41:11-04:00 — #9
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)
scannon — 2010-05-14T08:27:14-04:00 — #10
What version of rails are you running? Anything lower than 2.3.4 doesn't have the "seed" function.
axelsword — 2010-05-15T08:41:53-04:00 — #11
puts "rails seed database"
scannon — 2010-05-15T08:52:36-04:00 — #12
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
axelsword — 2010-05-15T10:49:31-04:00 — #13
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.
scannon — 2010-05-15T13:01:20-04:00 — #14
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.
axelsword — 2010-05-15T14:02:18-04:00 — #15
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...