Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Use of :as in Passing parameters to rails partials

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 326
    Comment on it

    While passing objects to partial we can change the name of the local variable in the partial and for that purpose we need to use the :as option.

    For example we have a partial _account.html.erb where we need to pass a collection @cutomers as local variable user . We will do it like this:

        <%= render partial: "account", collection: @cutomers, as: 'user' %> 
    

    _account.html.erb

    <div>
        <p><%= user.name%></p>
        <p><%= user.email%></p>
    </div>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: