Rails: Update data via link_to (without view)
<p>I'd like to update the data without form.</p>

<p>Although there are similar questions, they don't work for me.</p>

<p><a href="https://stackoverflow.com/questions/13687085/update-field-through-link-to-in-rails">Update field through link_to in Rails</a></p>

<p><a href="https://stackoverflow.com/questions/4751869/link-to-update-without-form">link_to update (without form)</a></p>

<p>What I'd like to do is to delete data as followings;</p>

<p>For example, delete <code>name</code> and <code>address</code> when delete link is clicked.</p>

<pre><code>id | name | address | ...
12 | aaa  | bbb     | ...
</code></pre>

<p>to</p>

<pre><code>id | name | address | ...
12 |      |         | ...
</code></pre>

<p>Although I tried some, error was displayed.(such as <code>ActionController::RoutingError</code>)</p>

<p><strong>schema</strong></p>

<pre><code>  create_table "rooms", force: :cascade do |t|
    t.string   "name"
    t.text     "address"
    ...
</code></pre>

<p><strong>model</strong></p>

<p>schedule.rb</p>

<pre><code>class Schedule &lt; ActiveRecord::Base
  belongs_to :user
  has_many :rooms, inverse_of: :schedule, dependent: :destroy
  accepts_nested_attributes_for :rooms, allow_destroy: true
  ...
</code></pre>

<p>room.rb</p>

<pre><code>class Room &lt; ActiveRecord::Base
  belongs_to :schedule, inverse_of: :rooms
  default_scope -&gt; { order(day: :asc) }
  ...
</code></pre>

<p><strong>view</strong></p>

<p>I'd like to add the link in <code>schedules/_schedule.html.erb</code>
It has the followings;</p>

<pre><code>  ...
  &lt;% schedule.rooms.each do |room| %&gt;
  ...
    &lt;% if room.name.present? %&gt;
        &lt;%= link_to "Delete", rooms_path(room, room:{address: nil}) , method: :put, data: { confirm: "You sure?"} %&gt;
  ...
</code></pre>

<p>I also tried another code as below, but they don't work.</p>

<pre><code>   &lt;%= link_to "Delete", rooms_path(room:{address: nil}) , method: :put, data: { confirm: "You sure?"} %&gt;

   &lt;%= link_to "Delete", rooms_path(room) , method: :put, params: {address: nil}, data: { confirm: "You sure?"} %&gt;
</code></pre>

<p>and so on.</p>

<p><strong>routes.rb</strong></p>

<pre><code>...
  resources :schedules do
    resources :events
  end

  resources :schedules do
    resources :rooms
  end

  resources :rooms do
    resources :events
  end
...
</code></pre>

<p><strong>rooms_controller.rb</strong></p>

<pre><code>...

def edit
  #nothing
end

def update
  @room = Room.find(params[:id])
  if @room.update(room_params)
    flash[:success] = "Room updated!"
    redirect_to itinerary_path(@room.itinerary) || current_user
  else
    render 'edit'
  end
end

def destroy
  @room = Room.find(params[:id])
  @room.destroy
  flash[:success] = "Room deleted"
  redirect_to schedule_path(@room.schedule) || current_user
end

private

  def room_params
    params.require(:room).permit(
      :id, :_destroy, :name, :address, :schedule_id, :day)
  end

...
</code></pre>

<p>It would be appreciated if you could give me any suggestion.</p>