Попытка передать идентификаторы от моего конца рельсов до конца. В моем контроллере Rails есть следующий фрагмент кода:
def count_vote
roster_id = params[:roster_id]
roster = Roster.find(roster_id)
newvote = roster.vote + 1
if roster.update({vote: newvote})
redirect_to rosters_path
end
end
Мой список рельсов для списка имеет следующий код:
<% @rosters.each do |roster| %>
<div class='each'>
<%= image_tag(roster['image_url'], class: 'image') %>
<%= hidden_field_tag(:roster_id, @roster.id) %>
<p class='name'> <%= roster['name'] %> </p>
<p class='title'> <%= roster['title'] %> </p>
<p> <%= roster['bio'] %> </p>
<p> <b> Want to work with <%= roster['name'] %>? </b> <%= link_to image_tag('thumbs-up.svg', class: 'thumbsup'), rosters_path, method: :patch %>
<br>
<%= roster['vote'] %> People have said Yes! </p>
<br>
</div>
<% end %>
Я пытаюсь передать идентификатор, используя скрытый тег поля, но я получаю следующую ошибку в журналах моего сервера rails:
Started PATCH "/rosters" for 127.0.0.1 at 2018-11-09 17:43:56 -0500
(0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
↳ /Users/sohel/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
Processing by RostersController#count_vote as HTML
Parameters: {"authenticity_token"=>"DJAtI8yNTlP1kQK/g/6o9jbdqxWEBBgKinzLtf8v8WrDnYCmrH+HQI5wTEjJ0T6rkKbBz0KA/q2M0yirluozQg=="}
Completed 404 Not Found in 14ms (ActiveRecord: 0.6ms)
ActiveRecord::RecordNotFound (Couldn't find Roster without an ID):
app/controllers/rosters_controller.rb:22:in `count_vote'
Поиск Roster.all в моей консоли ошибок возвращает следующее, для краткости я верну только первые два:
=> #<ActiveRecord::Relation [#<Roster id: 1, name: "John Smith", image_url: "https://d2eyrv63e6x6lp.cloudfront.net/wp-content/u...", title: "CTO / Co-founder", bio: "John has been programming since his dad bought him...", vote: 3, created_at: "2018-11-09 02:46:39", updated_at: "2018-11-09 02:46:39">, #<Roster id: 2, name: "Michael Thomas", image_url: "https://d2eyrv63e6x6lp.cloudfront.net/wp-content/u...", title: "Senior Software Engineer", bio: "Michael has been working as a back-end developer sin...", vote: 3, created_at: "2018-11-09 02:46:39", updated_at: "2018-11-09 02:46:39">