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

  • Home
  • SEARCH
  • 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 3357616
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:39:15+00:00 2026-05-18T02:39:15+00:00

I have a nice piece of functional and tested Ruby code that I would

  • 0

I have a nice piece of functional and tested Ruby code that I would like to integrate into a rails project:

require 'open-uri'

def shorten(url)
  open("http://is.gd/api.php?longurl=#{url}").read
rescue
  nil
end

I want to call the method shorten(url) from show.html.erb in the following way:

<% @shorturl = shorten("http://www.google.com/search?q=#{@bands.item.gsub(' ', '+')}+san+francisco") %>

I thought that placing the method shorten, within the model would work but it results in a NoMethodError (the require ‘open-uri’ is placed in the application_controller.rb)

undefined method `shorten' for #<ActionView::Base:0x1037e66a8>

Where should this method live? How can I get this to work? And what book or resource do you recommend that would make Rails seem less magical. Thank you in advance.

  • 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-18T02:39:15+00:00Added an answer on May 18, 2026 at 2:39 am

    My experience has been: if the method is dealing with database data, best to move it to Model. Even if it is about processing data from database data, it is recommended to move it into Model if possible, to have “lean controller” and “lean view” if possible.

    If the method is for generally helping to display something, then it belongs to the “helper”… for example, the h method is a classic example of “helping the View code”. You can add such methods to the application helper file, which is app/helpers/application_helpers.rb

    If it is not dealing with view and not dealing with data from the database, then you might consider it being a method of that controller class, or even a method of the application controller if it is very central to your application and should be inherited by all controllers.

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

Sidebar

Related Questions

I would like to have a nice template for doing this in development. How
An enum in Java implements the Comparable interface. It would have been nice to
This discussion started over here but I thought it would be nice to have
I have always made a point of writing nice code comments for classes and
I have a project that adds elements to an AutoCad drawing. I noticed that
I have a nice and lovely Django site up and running, but have noticed
So, I have a nice domain model built. Repositories handle the data access and
I could do this myself given time but does anyone have a nice asp.net
We are starting to use a Scrum process for development. We have a nice
I have created a nice silverlight control doing exactly what I want it to

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.