title: Ruby on Rails: How to print out a string and where does it display at?
body: <p>I know this is a trivial question. But I have search all over google but cannot find a simple answer to this question.</p>
  
  <p>Basically I have a line that says <code>&lt;%= link_to 'Run it', :method =&gt; 'doIt' %&gt;</code> in the view, then in the corresponding controller, I have the <code>doIt</code> method as follows:</p>
  
  <pre><code>def doIt
    puts "Just do it" 
  end
  </code></pre>
  
  <p>I just want to check that if i click on Run it, it will output the string "Just do it". I ran this on localhost and there is no errors, but I can't find the output "Just do it" anywhere. It is not displayed in the rails console or rails server log. I just want to know where does puts output the string to , where to find it ?</p>
  
  <hr>
  
  <p><strong>Round 2: So this is what I tried ....</strong> </p>
  
  <p>Added this line in the index.html.erb (which is the root)</p>
  
  <pre><code>&lt;%= link_to 'Run it', :method =&gt; 'do_it' %&gt;
  </code></pre>
  
  <p>and in the url, it is just basically <a href="http://localhost:3000/" rel="noreferrer">http://localhost:3000/</a> (since i route controller#index as root)</p>
  
  <p>The display is just an underlined 'Run it' that links to 'do_it' method in the controller.</p>
  
  <p>In the controller,  i include this method</p>
  
  <pre><code>def do_it
    logger.debug "Just do it"
  end
  </code></pre>
  
  <p>when i click on 'Run it', the url change to <a href="http://localhost:3000/gollum_starters?method=do_it" rel="noreferrer">http://localhost:3000/gollum_starters?method=do_it</a> and in the development.log, the following is written into it:</p>
  
  <pre><code>Started GET "/gollum_starters?method=do_it" for 127.0.0.1 at 2011-08-25 15:27:49 -0700
    Processing by GollumStartersController#index as HTML
    Parameters: {"method"=&gt;"do_it"}
    [1m[35mGollumStarter Load (0.3ms)[0m  SELECT "gollum_starters".* FROM "gollum_starters"
  Rendered gollum_starters/index.html.erb within layouts/application (3.6ms)
  Completed 200 OK in 16ms (Views: 7.7ms | ActiveRecord: 0.3ms)
  </code></pre>
  
  <p>Additionally, i tried all the logger.error/info/fatal/etc ... and Rails.logger.error/info/fatal/etc, all did not print out the line "Just do it" in the development log</p>
  
  <p>@Paul: I did not touch the environment folder or file, i assume by default when a new rails app is created, it is in development ?</p>
  
  <p>@Maz: Yes you are right, I am just trying to test if the do_it method is getting called. To do that, I just want to print something out in the controller. Can't think of any way simpler that just print a string out, but this problem is making me miserable. I am just using textmate, no IDE.</p>
  
  <hr>
  
  <p><strong>Round 3:</strong></p>
  
  <p>@Paul thx alot, but i encountered error</p>
  
  <p>My routes files is now:</p>
  
  <pre><code>resources :gollum_starters
  
  root :to =&gt; "gollum_starters#index"
  
  match 'gollum_starters/do_it' =&gt; 'gollum_starters#do_it', :as =&gt; 'do_it'
  </code></pre>
  
  <p>My index.html.erb is now:</p>
  
  <pre><code>&lt;%= link_to "Do it", do_it_path %&gt;
  </code></pre>
  
  <p>My gollum_starters_controller.rb</p>
  
  <pre><code>def do_it
    logger.debug 'Just do it'
  end
  </code></pre>
  
  <p>I am getting this error:</p>
  
  <blockquote>
    <p>Couldn't find GollumStarter with ID=do_it</p>
  </blockquote>
  
  <p>the error is in here, 2nd line:</p>
  
  <pre><code>def show
      @gollum_starter = GollumStarter.find(params[:id])
  
      respond_to do |format|
        format.html # show.html.erb
        format.xml  { render :xml =&gt; @gollum_starter }
      end
    end
  </code></pre>
  
  <p>I wonder why does it route to show ? When i click do_it, it actually goes to localhost:3000/gollum_starters/do_it which is correct, but apparently the error points to the show method ?</p>
  
  <hr>
  
  <p><strong>Round 4:</strong></p>
  
  <p>@Paul, i shifted resources :gollum_starters down:</p>
  
  <pre><code>root :to =&gt; "gollum_starters#index"
  
  match 'gollum_starters/do_it' =&gt; 'gollum_starters#do_it', :as =&gt; 'do_it'
  
  resources :gollum_starters
  </code></pre>
  
  <p>but got this error (omg i wanna kill myself), </p>
  
  <blockquote>
    <p>Template is missing</p>
    
    <p>Missing template gollum_starters/do_it with {:handlers=>[:erb, :rjs,
    :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in
    view paths "~/project_name/app/views"</p>
  </blockquote>
  
  <p>:/</p>
  
  <p>---------- <strong>Answer to Round 4</strong> ------------</p>
  
  <p>Basically as the error explains, there is no template(i.e a webpage) to show hence error thrown. The solution is to add a redirect_to  , in this case I redirect to root_url. </p>
  
  <pre><code>def do_it
    logger.debug 'Just do it'
    redirect_to(root_url)
  end
  </code></pre>
  
  <p>Everything works now, "Just do it" finally outputs to development.log and the rails server console.</p>
  
  <p><em>Thank you Maz and Paul and Andrew for helping me out. Learn a lot.</em> </p>