How to pass variables to partial in Rhomobile

2019-08-09 03:27发布

问题:

I have a partial where i need show the value of variable catchedEvent,

Partial

<div class="eventList">Here to show the value of the variable</div>

On my erb page i'm calling this using

<%= render :partial =>"mypartial" %>

I can't get the way to pass the variable to it. Please help.

回答1:

You can use the locals or collections as specified over here http://docs.rhomobile.com/rhodes/ui#advanced-usage-of-render

<%= render :partial =>"mypartial", :locals => { :event => "myevent" } %>

Then on partial, use it like

<div class="eventList"><%= event %></div>

Second, if you assign some value to the instance variable in the controller,

@event = "myevent"

then you can directly access it inside the partial as below,

<div class="eventList"><%= @event %></div>

These are some of the ways you can use to pass the variables.