Note that there are some explanatory texts on larger screens.

plurals
  1. POHow update an attribute binded on a check box when clicking on it?
    primarykey
    data
    text
    <p>First of all, thanks in advance for your attention : I am pretty noob in Rails and I am facing a problem that does not seem difficult but I have some troubles implementing it.</p> <p>Here is my question : I am displaying a list of "Recommendations" using the following partial : </p> <pre><code>&lt;table class="recommendations" summary="User recommendations"&gt; &lt;%= render @recommendations%&gt; &lt;/table&gt; </code></pre> <p>It calls the next partial for each of the dispayed "Recommendations" : </p> <pre><code>&lt;tr&gt; &lt;td class="recommendations"&gt; &lt;span class="content"&gt; &lt;%= wrap(recommendation.content)%&gt; &lt;/span&gt; &lt;span class="timestamp"&gt; Posted &lt;%=time_ago_in_words(recommendation.created_at)%&gt; ago. &lt;/span&gt; &lt;/td&gt; &lt;td&gt; &lt;%= form_for current_user.recommendations.find(:id =&gt; recommendation.id) do |f| %&gt; &lt;label&gt;Display&lt;/label&gt;&lt;%= f.check_box :displayed, :onclick =&gt; "update"%&gt; &lt;% end %&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre> <p>So, I would like to bind the recommendation.displayed attribute in the checkbox and update automatically the recommendation resource when the checkbox is checked or not.</p> <p>For now, I can not access to the appropriate "recommendation" instance to pass to the form_for because I have the following error : </p> <pre><code>Unknown key(s): id </code></pre> <p>And then I am not sure that the </p> <pre><code>:onclick =&gt; "update" </code></pre> <p>will perform what I want to do : call the rest "PUT" method to update the resource in database.</p> <p>Could you please help me ?</p>
    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.
    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