|
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...
Comments
Kalid said over 6 years ago:
Thanks for the tip about the application helpers! I was looking for just that.
Peter Marklund said over 6 years ago:
Another great thing about the console that I hadn't been aware of is that it does code completion.
Peter Marklund said over 6 years ago:
An easier way to test your helpers is to use something like:
MyController.send(:view_class).new.my_helper_method



Joel Junström said over 6 years ago:
Cheeses =)
Sjukt att jag missat reload!
bockar och tackar