Templates and partials


#1

i´m having something like this:

<%= render(:partial => ‘interview’, :object => @interviews)%>

now, within the view, i´d like to pass the id-parameter to select a
certain
interview.
like this (although this code is probably wrong):

<%= render(:partial => ‘interview’, :object => @interviews, :id =>
1237)%>

basically, i need the view to tell the controller which interview to
choose.
any idea how to achieve this?


#2

Use :locals:

<%= render(:partial => ‘interview’, :locals => { :id => 1237 })%>

Check the docs on ActionController::Base
(http://api.rubyonrails.com/classes/ActionController/Base.html#M000171)


#3

how can i access the id (local) within the controller to choose the
right
interview?


#4

What do you mean? You retrieve the right object from your controller
and pass that object to your partial.


#5

As far as I understand:

First the controller is executed by rails
Then the view is rendered
And that’s it

So there will be no way to again execute the controller after
the view has been rendered. This means, no communication from view to
the controller is possible. Only from controller to view. And that’s how
it
should be. If the decision in the view depends on some user action I
would
suggest using Ajax. Otherwise I would rethink your problem and solve it
in the controller where logic is supposed to be.

On Fri, 02 Dec 2005 11:12:13 +0100, patrick k
removed_email_address@domain.invalid


#6

as mentioned before:
basically, i need the view to tell the controller which interview to
choose.

well, maybe that´s not possible. maybe i need components.


#7

i already thought it might (and should) be that way.
guess i have to re-think my problem.

thanks for your answer.