{"id":144,"date":"2008-08-21T08:54:31","date_gmt":"2008-08-21T16:54:31","guid":{"rendered":"http:\/\/www.codebelay.com\/blog\/?p=144"},"modified":"2023-08-22T15:02:33","modified_gmt":"2023-08-22T21:02:33","slug":"the-rails-console-makes-test-object-creation-and-debuggingeasy","status":"publish","type":"post","link":"https:\/\/www.codebelay.com\/blog\/2008\/08\/21\/the-rails-console-makes-test-object-creation-and-debuggingeasy\/","title":{"rendered":"The Rails Console Makes Test Object Creation and Debugging Easy"},"content":{"rendered":"<p>I really like how the Rails console solves the problems of test object creation and debugging.<\/p>\n<p>Usually, a web developer will push code to the webserver and hit shift-reload on the web browser. With the Rails console, you can avoid all that shift-reload madness.<\/p>\n<p>If I wanted to create 10000 blog posts for testing, I could do something like this:<\/p>\n<p><strong>script\/console<br \/>\n10000.times<br \/>\n{ |i| Post.create(:title => &#8220;post number: &#8221; + i.to_s, :body => &#8220;autogen Booyah!&#8221;) }<br \/>\n<\/strong><br \/>\nThrough the console I can also do debugging pretty easily:<\/p>\n<p><strong>>> p = Post.find 888<\/strong><\/p>\n<p>And get this as output:<\/p>\n<pre>\n=> #<Post id: 888, title: \"post number: 888\", body: \"autogen Booyah!\", created_at: \n\"2008-08-09 20:31:57\", updated_at: \"2008-08-09 20:31:57\"><\/pre>\n<p>A lot of problems in Rails are just solved by running script\/console and checking the values of certain variables that are pretty hard to get at through a web browser.<\/p>\n<p>There is pretty much no limit to what can be done through the Rails console. <a href=\"http:\/\/tektastic.com\/\">Konstantin Gredeskoul<\/a>, web developer and songwriter, has found a way to <a href=\"http:\/\/tektastic.com\/2006\/12\/ruby-on-rails-how-to-load-session.html\">load session data through the console<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I really like how the Rails console solves the problems of test object creation and debugging. Usually, a web developer will push code to the webserver and hit shift-reload on the web browser. With the Rails console, you can avoid all that shift-reload madness. If I wanted to create 10000 blog posts for testing, I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,107,33],"tags":[100,114,118,392],"class_list":["post-144","post","type-post","status-publish","format-standard","hentry","category-how-to","category-ruby-on-rails","category-webapps","tag-debugging","tag-rails","tag-rails-console","tag-ruby-on-rails"],"_links":{"self":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/posts\/144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/comments?post=144"}],"version-history":[{"count":0,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/posts\/144\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/media?parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/categories?post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/tags?post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}