I am trying to pass a variable to a partial so that it can be called within the partial
This is how i am rendering the partial
= render :partial => "layouts/reveal_delete", :resource => @schedule
and this is how i am calling the variable within the partial, though it doesnt appear to be working
#RevealDelete.reveal-modal
%a.close-reveal-modal ×
%h3= "Delete #{@resource}"
%p Are you sure you want to delete this?
=link_to "Delete #{@resource}", @resource, :method => :delete, :class => "button close-reveal-modal"
%a.button.alert.close-reveal-modal Cancel
Call it this way:
And then within the partial, you can use it by referring to
resource(no@), like this:Typically, though, you would name your local variable
scheduleto match the instance variable, so:And then you can refer to
schedulein your partial.Also if you want, you can drop the
:partialand:localsoption keys, and use this shorter syntax:Here, Rails assumes that if you pass in a string as your first argument, then the first argument is your partial name and the remainder is interpreted as local variable assignments. Here’s an answer discussing this syntax:
Also more info in the docs.