Rails console

Viewing data
You can easily see what data is in the system and run quick queries and commands on it from the console. For example, try this:

rails console Crop.all crop = Crop.find('tomato') crop.en_wikipedia_url crop.scientific_names.first.scientific_name exit

Creating ad-hoc test data
Sometimes you need to create some test data quickly for a manual test. The best way to do this is with rails console, which lets you execute Ruby code in the context of your development environment.

For instance, to create a test crop, open a terminal in your Growstuff directory, and type

rails console Crop.create! system_name: "Tomato", en_wikipedia_url: "http://blah/" exit

This will show you the SQL generated (which will let you see the slug added), and then you can run "rails server" and see it in action on your localhost site (http://localhost:3000/crops/$slug).

To create a test user, type

rails console user = User.create! :username => "test", :password => "password", :email => "test@example.com", :tos_agreement => true user.confirm! exit

You should now be able to log in to your local Growstuff instance with username "test" and password "password". (Note there are also Test users available so you should no longer (or very seldom) need to do this. But the principle holds for any test data you might want to fool around with.)

Running explicit SQL
results = ActiveRecord::Base.connection.execute("select column_name from INFORMATION_SCHEMA.COLUMNS where table_name='users'") results.each { |r| puts r }