0

How can I pass a variable to a partial using this code? :

<%= render @performance_indicator.improvement_actions.order("created_at DESC") %>

I want to pass "id=1" and then in _improvement_action, use that variable like:

<%= id %>

EDIT:

This is my improvement_action partial:

https://gist.github.com/luisamaro0/6597084f2de1dc33cde7c014ea9f23a5

1

3 Answers 3

3

You can pass a local variable like so:

render "a_partial", :a_local_variable => whatever, :another_variable => another

See this question for more details: Rails 3, passing local variable to partial

Sign up to request clarification or add additional context in comments.

9 Comments

i cant pass a created local variable ?
Yes, you can, my mistake for misunderstanding your question. I've updated my answer and linked you to a similar question.
I saw that question before and tried like that: <%= render @performance_indicator.improvement_actions, :a_local_variable => 'whatever' %> but dont work, when calling the variable in the partial
It works for me, are attempting to access the local variable as a symbol? (You shouldn't be)
im trying to access like this: <%= a_local_variable %>
|
1

you can pass a variable like this

<%= render partial: 'partial_name', locals: {id: '1'} %>

3 Comments

i tried like this but it doesnt work <%= render partial: 'improvement_actions/improvement_action', locals: {id: '1'}, collection: @performance_indicator.improvement_actions %>
undefined local variable or method `id'
can you post improvement_action partial??
0

Try this syntax out:

<%= render @performance_indicator.improvement_actions, locals: { local_variable: 1 %>
# then <%= local_variable %>

1 Comment

undefined local variable or method `local_variable'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.