diff --git a/CHANGELOG.md b/CHANGELOG.md index aa8047ed..8211dc97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Use `friendly_id` gem for ease of use with slugs in URLs. ([#64]) - Introduce feature pages for each feature in the dataset. ([#64]) - Display subfeatures on feature pages when relevant. ([#66]) +- Link to parent feature on feature page when relevant. ([#67]) ### Changed - Browser pages now have URLs like `/browsers/chrome` rather than `/browsers/1`. ([#62]) @@ -105,6 +106,7 @@ First tagged release, includes some basic functionality. [#64]: https://github.com/connorshea/mdn-compat-data-explorer/pull/64 [#65]: https://github.com/connorshea/mdn-compat-data-explorer/pull/65 [#66]: https://github.com/connorshea/mdn-compat-data-explorer/pull/66 +[#67]: https://github.com/connorshea/mdn-compat-data-explorer/pull/67 [Unreleased]: https://github.com/connorshea/mdn-compat-data-explorer/compare/v0.4.0...HEAD [0.4.0]: https://github.com/connorshea/mdn-compat-data-explorer/compare/v0.3.1...v0.4.0 diff --git a/app/controllers/features_controller.rb b/app/controllers/features_controller.rb index 98394045..5a56d0db 100644 --- a/app/controllers/features_controller.rb +++ b/app/controllers/features_controller.rb @@ -92,6 +92,11 @@ def show @browsers = get_browsers @subfeatures = Feature.where("name ~* ?", "^#{@feature.name}.*").where.not(slug: params[:slug]) + + parent_feature_name = @feature.name.split(/\./) + parent_feature_name.pop + parent_feature_name = parent_feature_name.join(".") + @parent_feature = Feature.find_by(name: parent_feature_name) end private diff --git a/app/views/features/show.html.erb b/app/views/features/show.html.erb index e711ad61..9f51ce17 100644 --- a/app/views/features/show.html.erb +++ b/app/views/features/show.html.erb @@ -3,6 +3,9 @@
+ <% if @parent_feature %> +

Parent: <%= link_to @parent_feature.name, feature_path(@parent_feature.slug) %>

+ <% end %>

<%= @feature.name %>

@@ -23,5 +26,4 @@
<% end %> -