I have a model organismereferent which has a boolean value named active. What I'm trying to do is depending on what value it has do a different action.
So if it's active the button shows deactivate and allows the user to set active to false. So after that the button should show activate which will allow the user to set active back to true.
I tried making a method in my controller then calling that method from my index view but it gives me a No route matches [POST] "/organismereferents/8". I'm pretty new to Ruby on Rails so there must be an easier way to accomplish that
View:
<table class="table table-hover">
<tr>
<th>Nom Organisation</th>
<th>Site Web</th>
</tr>
<% @organismes.each do |organisme| %>
<tr>
<td><%= organisme.nom_organisation %></td>
<td><%= organisme.site_web %></td>
<td><%= link_to 'Show', organismereferent_path(organisme), class: 'btn btn-info' %></td>
<td><%= link_to 'Edit', edit_organismereferent_path(organisme), class: 'btn btn-warning' %></td>
<% if organisme.active == false %>
<td><%= link_to 'Activate', organismereferent_path(organisme), class: 'btn btn-danger',
method: :activate,
data: { confirm: 'Are you sure?' } %></td>
<% else %>
<td><%= link_to 'Deactivate', organismereferent_path(organisme), class: 'btn btn-danger',
method: :deactivate,
data: { confirm: 'Are you sure?' } %></td>
<% end %>
</tr>
<% end %>
</table>
Controller:
def index
@organismes = Organismereferent.all
end
def deactivate
@organisme = Organismereferent.find(params[:id])
@organisme.active = false
end
def activate
@organisme = Organismereferent.find(params[:id])
@organisme.active = true
end
If you need any more information I will be glad too add it.
Routes:
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
get 'master/index'
resources :organismereferents
# Notre page principal
root 'master#index'
end

rake routesand post the result.