Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6366813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:28:10+00:00 2026-05-25T00:28:10+00:00

I know this is a trivial question. But I have search all over google

  • 0

I know this is a trivial question. But I have search all over google but cannot find a simple answer to this question.

Basically I have a line that says <%= link_to 'Run it', :method => 'doIt' %> in the view, then in the corresponding controller, I have the doIt method as follows:

def doIt
  puts "Just do it" 
end

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 ?


Round 2: So this is what I tried ….

Added this line in the index.html.erb (which is the root)

<%= link_to 'Run it', :method => 'do_it' %>

and in the url, it is just basically http://localhost:3000/ (since i route controller#index as root)

The display is just an underlined ‘Run it’ that links to ‘do_it’ method in the controller.

In the controller, i include this method

def do_it
  logger.debug "Just do it"
end

when i click on ‘Run it’, the url change to http://localhost:3000/gollum_starters?method=do_it and in the development.log, the following is written into it:

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"=>"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)

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

@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 ?

@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.


Round 3:

@Paul thx alot, but i encountered error

My routes files is now:

resources :gollum_starters

root :to => "gollum_starters#index"

match 'gollum_starters/do_it' => 'gollum_starters#do_it', :as => 'do_it'

My index.html.erb is now:

<%= link_to "Do it", do_it_path %>

My gollum_starters_controller.rb

def do_it
  logger.debug 'Just do it'
end

I am getting this error:

Couldn’t find GollumStarter with ID=do_it

the error is in here, 2nd line:

def show
    @gollum_starter = GollumStarter.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @gollum_starter }
    end
  end

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 ?


Round 4:

@Paul, i shifted resources :gollum_starters down:

root :to => "gollum_starters#index"

match 'gollum_starters/do_it' => 'gollum_starters#do_it', :as => 'do_it'

resources :gollum_starters

but got this error (omg i wanna kill myself),

Template is missing

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”

:/

———- Answer to Round 4 ————

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.

def do_it
  logger.debug 'Just do it'
  redirect_to(root_url)
end

Everything works now, “Just do it” finally outputs to development.log and the rails server console.

Thank you Maz and Paul and Andrew for helping me out. Learn a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:28:11+00:00Added an answer on May 25, 2026 at 12:28 am

    That link_to does not do what you think it does the value for :method is referring to the HTTP verbs.

    Taken from the docs for ActionView::Helpers::UrlHelper

    :method – Symbol of HTTP verb. Supported verbs are :post, :get, :delete and :put. By default it will be :post.

    You would need to define a route in your routes.rb file that uses your method

    # The order of routes is important as the first matched will be used
    # therefore the match needs to be above 'resources :controller'
    match 'controller/do_it' => 'controller#do_it', :as => 'do_it'
    
    resources :gollum_starters # <--- This needs to be below the match or this will catch first
    
    • The controller/do_it is the route to be matched
    • The controller#do_it is the controller followed by the action to be used (separated by #)
    • The value for :as creates the path do_it_path that can be used in your link_to

    Your link_to may look something like

    <%= link_to "Do it", do_it_path %>
    

    And to complete the lifecycle of a request you will need to add a view to be rendered

     app/views/gollum_startes/do_it.html.erb # <-- Add file 
    

    Summary
    Doing all of this creates a bit of a mess just to print something out to the logs, but it should help you understand the whole lifecycle a bit better now. Plus this answers serves as a document to help you rewind this mess.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this seems to be a trivial question but I could not find
I know this is an old question, but I have spend any hours on
I know this is probably something simple but I can't seem to find anything
I know this seams a trivial question, but how can I disable the annoying
Many will find this question quite trivial, but since I'm quite new on iOS
I know this must be a trivial question, but I've tried many different ways,
I realise this is a trivial question but I don't have access to a
I know this is a beginner's question, but I've been searching online and all
Hi I know this question is a bit trivial. I googled it but could
I have a question that must surely seem very trivial, but the answer has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.