mercredi 25 octobre 2017

Rails - using url: versus href: when sending a path to the controller. What makes them different?

This is a followup question to an earlier one of mine: Rails 5 - use collection_radio_buttons to open a partial with nested models?

We were able to make a radio_button send a request to open a partial with content related to the button being clicked. (yay!) The main change, AFAIK, was when we replaced href: with url: in the button's arguments.

What I don't understand yet is how these two things differ in their execution.

Here's the snippets of each version:

<% System.all.each do |rt| %>
  <label>
    <%= f.radio_button :system_id, rt.id, data:{:remote => true, 'data-target' => 
   '@applicationList'}, href: system_applications_path(:system_id => rt.id, 
   :schedule_id => params['id']), class: 'remote-input', onclick: 
   "#applicationsList" %>
  </label>
<% end %>

Versus:

<% @systems.each do |a|
  <label class="btn btn-sm btn-default">
    <%= f.radio_button :system_id, a.id, :data => {url:system_applications_path(:system_id 
    => a.id, :schedule_id => params['id']), 'data-target' => '#applicationList'+a.id.to_s,
    :remote => true} %>
    <%= a.system_nm %>
  </label>
<% end %>

In particular:

 href: system_applications_path(:system_id => rt.id, 
   :schedule_id => params['id']),

vs:

{url:system_applications_path(:system_id 
    => a.id, :schedule_id => params['id']),




Aucun commentaire:

Enregistrer un commentaire