Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing data to a rails partial
    primarykey
    data
    text
    <p>Edit: Solution Worked Perfectly. <a href="http://api.rubyonrails.org/classes/ActionController/RecordIdentifier.html" rel="nofollow noreferrer">dom_id</a></p> <p>I am trying to pass data to a partial and use it to change roles of a user. Right now it will only change the roles of one user. When it is rendered it only displays and acts on the roles of <code>User.first</code></p> <p>Where it is rendered. i pass the user in locals. as per <a href="https://stackoverflow.com/questions/4700617/pass-a-variable-into-a-partial-rails-3">this post</a> I used the second answer because the first one didnt work and gave me errors. </p> <pre><code>&lt;%= render :partial =&gt; 'roles', :locals =&gt; { :user =&gt; user } %&gt; </code></pre> <p>Below is the partial _role.html.erb</p> <pre><code>&lt;div id="roleModal" class="reveal-modal"&gt; &lt;%= semantic_form_for user, :url =&gt; user_path(user), :html =&gt; {:method =&gt; :put } do |f| %&gt; &lt;h3&gt;Change Role&lt;/h3&gt; &lt;div class="reveal-modal-body"&gt; &lt;%= f.input :roles, :as =&gt; :check_boxes, :input_html =&gt; { :selected =&gt; user.role_ids } %&gt; &lt;/div&gt; &lt;a class="close-reveal-modal"&gt;&amp;#215;&lt;/a&gt; &lt;%= f.action :submit, :as =&gt; :button %&gt; &lt;% end %&gt; </code></pre> <p></p> <pre><code>&lt;% @users.each do |user| %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= link_to user.name, user %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= user.email %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= user.created_at.to_date %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= user.roles.first.name.titleize unless user.roles.first.nil? %&gt;&lt;/td&gt; &lt;td&gt; &lt;a href="roles#&lt;%= user.id %&gt;" data-reveal-id="roleModal" class="button" type="button"&gt;Change role&lt;/a&gt; &lt;%= render :partial =&gt; 'roles', :locals =&gt; { :user =&gt; user } %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;% end %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload