PiKaY
PiKaY

Reputation: 289

How to get data from a URL inside a rails controller?

I have a controller method say

def my_method
 @gibbon = <data needed>
 render :something
end

and i have a URL say

http://exampleforme.com/example1

which returns a certain text, how to get this text inside my controller method from the URL?

I am using rails 2.8

Upvotes: 1

Views: 4480

Answers (2)

Boat Pathompon
Boat Pathompon

Reputation: 42

can you show me your route file ?

but I think if you want "example1" text in url you can call params[:id] in your controller

@text = params[:id]

Upvotes: -2

AlexT
AlexT

Reputation: 696

You could use Net::HTTP to get that URL as a string:

@gibbon = Net::HTTP.get(URI.parse("http://exampleforme.com/example1"))

See the API docs for more information.

Note: that this could impact your response time if that URL is slow to respond.

Upvotes: 7

Related Questions