Micheal
Micheal

Reputation: 2322

ruby on rails handling url parameters

I come from a PHP background and am having lot of trouble understanding how to handle rails handles post,get request data etc.

I have have a hyperlink that I make it go to

http:/localhost/clients/1/?office_id=2

In my controller, I tried

def show
   @office_id=params[:office_id]
end

in my view I am just trying to display that variable

@office_id

But it does not display anything. Is my hyperlink incorrect or I am missing something else?

Upvotes: 0

Views: 2126

Answers (3)

Micheal
Micheal

Reputation: 2322

I apologize. In my view I was displaying it as:

- @office_id

I didn't realize the above was just evaluating it and not displaying it.

Changing it to

= @office_id 

made it work.

Upvotes: 2

Trip
Trip

Reputation: 27114

Your controller :

def show
  # assuming you have an Office object..
  @office = Office.find(params[:office_id])
end

Then in your view :

= @office.attribute # or if you just want to display its ID then : @office.id

Upvotes: 1

portlandrock
portlandrock

Reputation: 298

Use http:/localhost/clients/1?office_id=2, without the last / in your url. As Benjamin said also, look at your log file to see if the parameter is coming through to your controller method. If it isn't, then you have something else going on.

Upvotes: 0

Related Questions