Peter Marklund's Home |
Rails script/console - Did you know it could do all this?
Yesterday someone pointed out some features of the Rails console that I had missed out on. Here are some objects and commands to be aware of:
- reload! - reloads the application with your model classes. Useful when you've made changes to your code
-
app - an ActionController::Integration::Session object that lets you run through whole integration tests from the console. Use app(true) to create a new session. Here is a sample of commands:
- app.get("/")
- app.assert_response :success
- app.response
- app.request
- app.assert_tag
- app.flash
- app.assigns
- app.assert_template
-
helper - an object with all the ActionView::Helpers::* modules mixed in. Methods that you can experiment with include: link_to, url_for, pluralize, form_tag, date_select, link_to_remote. If you would like to experiment with your application helpers you can do this:
>> class MyHelper >> include ApplicationHelper >> include all the helpers you wish to test here... >> end => MyHelper >> my_helper = MyHelper.new => #<MyHelper:0x25e2710> >> (my_helper.methods - Object.methods) => list of helper methods to play with follows...