Add link to an (empty) edit action
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
<th><%= model_class.human_attribute_name(:title) %></th>
|
||||
<th><%= SDG::Goal.model_name.human(count: 2).upcase_first %></th>
|
||||
<th><%= SDG::Target.model_name.human(count: 2).upcase_first %></th>
|
||||
<th><%= t("admin.actions.actions") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@@ -15,6 +16,14 @@
|
||||
<td><%= record.title %></td>
|
||||
<td><%= record.sdg_goal_list %></td>
|
||||
<td><%= record.sdg_target_list %></td>
|
||||
<td>
|
||||
<%= render Admin::TableActionsComponent.new(
|
||||
record,
|
||||
actions: [:edit],
|
||||
edit_text: t("sdg_management.actions.edit"),
|
||||
edit_path: edit_path_for(record)
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -16,4 +16,13 @@ class SDGManagement::Relations::IndexComponent < ApplicationComponent
|
||||
def model_class
|
||||
records.model
|
||||
end
|
||||
|
||||
def edit_path_for(record)
|
||||
{
|
||||
controller: "sdg_management/relations",
|
||||
action: :edit,
|
||||
relatable_type: record.class.name.tableize,
|
||||
id: record
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,10 @@ class SDGManagement::RelationsController < SDGManagement::BaseController
|
||||
@records = relatable_class.accessible_by(current_ability).order(:id).page(params[:page])
|
||||
end
|
||||
|
||||
def edit
|
||||
@record = relatable_class.find(params[:id])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def relatable_class
|
||||
|
||||
1
app/views/sdg_management/relations/edit.html.erb
Normal file
1
app/views/sdg_management/relations/edit.html.erb
Normal file
@@ -0,0 +1 @@
|
||||
<h2><%= @record.title %></h2>
|
||||
@@ -1,5 +1,7 @@
|
||||
en:
|
||||
sdg_management:
|
||||
actions:
|
||||
edit: "Manage goals and targets"
|
||||
header:
|
||||
title: "SDG content"
|
||||
menu:
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
es:
|
||||
sdg_management:
|
||||
actions:
|
||||
edit: "Asignar objetivos y metas"
|
||||
header:
|
||||
title: "Contenido ODS"
|
||||
menu:
|
||||
|
||||
@@ -9,8 +9,10 @@ namespace :sdg_management do
|
||||
types_constraint = /#{types.join("|")}/
|
||||
|
||||
get "*relatable_type", to: "relations#index", as: "relations", relatable_type: types_constraint
|
||||
get "*relatable_type/:id/edit", to: "relations#edit", as: "edit_relation", relatable_type: types_constraint
|
||||
|
||||
types.each do |type|
|
||||
get type, to: "relations#index", as: type
|
||||
get "#{type}/:id/edit", to: "relations#edit", as: "edit_#{type.singularize}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -70,5 +70,17 @@ describe "SDG Relations", :js do
|
||||
expect(page).to have_content "6.1, 6.2"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "shows link to edit a record" do
|
||||
create(:budget_investment, title: "Build a hospital")
|
||||
|
||||
visit sdg_management_budget_investments_path
|
||||
|
||||
within("tr", text: "Build a hospital") do
|
||||
click_link "Manage goals and targets"
|
||||
end
|
||||
|
||||
expect(page).to have_css "h2", exact_text: "Build a hospital"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user