OVERTONE
OVERTONE

Reputation: 12187

Passing current page id to a link_to (Ruby/ Rails)

Apologies if this seems a bit vague.

Basically I have a page which loads content based on id. I'm trying to put links withing it like this

<%= link_to 'mypage', {:action => 'mypageload', :id => '1'},{:class=>'mypages'}%>

What I'd like to do is pass the id of the current page into this link.

So something like

:id => 'params[:id]'

Is there a way to do this?

Upvotes: 0

Views: 1904

Answers (2)

Arun Kumar Arjunan
Arun Kumar Arjunan

Reputation: 6857

Remove the single quotes: :id => params[:id]

Upvotes: 2

DanneManne
DanneManne

Reputation: 21180

Yes, you can use the params variable in the views. In your example you put the params inside quotes making it a string. Just leave those out and you should be fine, like this:

<%= link_to 'mypage', {:action => 'mypageload', :id => params[:id]},{:class=>'mypages'}%>

Upvotes: 1

Related Questions