mardi 20 septembre 2016

Rails - Save item from index and write it to a new Model

I have a list of tweets on my index (Twit model, twits controller) with a checkbox aside. What I'd like to do is to save checked tweets to an other model (Repost model, reposts controller).

The Repost model will have the same attribute as the Twit one. I just want to select specific tweets from my index View and save them to the Repost model.

Here is my View:

<%= form_tag reposts_path do %>
<ul>
  <% @twits.each do |twit| %>
    <li>
      <%= twit.like %> likes
      <%= check_box_tag "repost_twit_#{twit.id}"  %> -
      <%= link_to twit_path(twit) do %>
        <i class="glyphicon glyphicon-eye-open"></i>
      <% end %> -
      <%= link_to twit_path(twit), method: :delete do %>
        <i class="glyphicon glyphicon-trash"></i>
      <% end %>
    </li>
  <% end %>
</ul>
<ul>
  <li></li>
</ul>
<%= submit_tag "Add to your Repost library", class: "btn btn-primary" %>

I have the logic as I succeed doing it within my Rails console, but I can't do it within the app... It will be like this Repost.create(like:Twit.first.like)

I am obviously missing something. Thanks for your help.




Aucun commentaire:

Enregistrer un commentaire