Params question

I’m a little embarrassed to ask this but I have a url that is like:

foo/bar/5?start=45

and in foo_controller I’m trying to access it like so:

def bar
@start_time = get_start_time(params)
end

def get_start_time(params)
if params[‘start’].to_s != nil
return ‘?start=’+params[‘start’].to_s
end
end

I’m coming from PHP/.NET so RESTfulness is a little difficult for me
to wrap my head around. Maybe I’m googling on the wrong terms but I
haven’t had any luck yet…Any advice would be very appreciated.

I’m not sure what exactly your trying to do with the get_start_time
method when it looks like you just want:

@start_time = params[:start]

Here is a good REST pdf.
http://www.rubyinside.com/restful-rails-development-pdf-released-392.html

joshuajnoble wrote:

Hi thanks for the respone. I just need to have @start_time = “?
start=”+params[:start] only if params[:start] isn’t empty, i.e. if the
url isn’t

foo/bar/5?start=45

but is

foo/bar/5

def get_start_time(params)
if !params[‘start’].nil?
“?start=#{params[‘start’]}”
end
end

or maybe just

def get_start_time(params)
if params[‘start’]
“?start=#{params[‘start’]}”
end
end

let me know if it works :slight_smile:

That works perfectly, thank you so much. I’m curious how ruby, like,
well anything else I work with, doesn’t require a return statement:

def get_start_time(params)
if params[‘start’]
return “?start=#{params[‘start’]}”
end
end

Hi thanks for the respone. I just need to have @start_time = “?
start=”+params[:start] only if params[:start] isn’t empty, i.e. if the
url isn’t

foo/bar/5?start=45

but is

foo/bar/5

The value returned by a Ruby method is the value of the last
expression evaluated.

Read:
http://www.rubycentral.com/book/intro.html

Best,
Thomas

Am 04.03.2007 um 17:44 schrieb joshuajnoble: