Note that there are some explanatory texts on larger screens.

plurals
  1. POEdit value in table via button click (Ruby on Rails)
    primarykey
    data
    text
    <p>I'm a little ashamed, because for over 2 hours now I can't figure out how to do this. But I'm rather new to Rails, so bear with me :)</p> <p>I have two groups of users: Posters and Doers Then there is a model "Assignments". Assignments are created by Posters (have a belong_to relationship with them). Doers can then select assignments from a pool of unassigned ones and assign them to themselves (that's why Assignments also have a belong_to relation with Doers).</p> <p>On the page itself I have this code at the moment (changed it like 20 times over the last hour):</p> <pre><code>&lt;table class="table"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Title&lt;/th&gt; &lt;th&gt;Assign to me&lt;/th&gt; &lt;/tr&gt; &lt;/thhead&gt; &lt;tbody&gt; &lt;% @assignments.each do |assignment| %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= assignment.title %&gt;&lt;/td&gt; &lt;td&gt; &lt;%= link_to(edit_assignment_path(assignment), :doer =&gt; current_doer.id, confirm: 'Really take this assignment on?') do%&gt; &lt;i class="icon-folder-open", alt="assign"&gt;&lt;/i&gt; &lt;% end %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;% end %&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>With this code in the AssignmentController:</p> <pre><code>def edit @assignment = Assignment.find(params[:id]) @doer = Doer.find(params[:doer]) if @patient.assign(@doer) redirect_to dashboard_index_path, notice: 'Successfully assigned to you' else redirect_to dashboard_index_path, alert: 'Error while trying to assign to you' end end </code></pre> <p>And this in Assignment.rb :</p> <pre><code>def assign(current_doer) if self.doer_id != nil then false else self.doer_id &lt;&lt; current_doer true end end </code></pre> <p>As you can see I'm logged in as a Doer in this example. And I can't for the life of me figure out how to do this correct and clean!</p> <p>I also tried variations of the link_to code part, the assign function and so on. At the moment I get the error, that @doer = Doer.find(params[:doer]) cannot search for an id of Nil. I know that this means that I don't really send the doer_id parameter along correctly, but I'm at my beginners-knowledge end.</p> <p>Thank you very much for helping me out here.</p> <p>Greetings, Lordylike</p>
    singulars
    1. This table or related slice is empty.
    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.
    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