diff --git a/app/assets/javascripts/application_non_webpack.js b/app/assets/javascripts/application_non_webpack.js index a761af074..8e3c3994b 100644 --- a/app/assets/javascripts/application_non_webpack.js +++ b/app/assets/javascripts/application_non_webpack.js @@ -1,5 +1,3 @@ // All webpack assets in development will be loaded via webpack dev server // turbolinks comes from npm and is listed in webpack.client.base.config.js - -//= require rails_startup diff --git a/app/assets/javascripts/rails_startup.js b/app/assets/javascripts/rails_startup.js deleted file mode 100644 index 21eb42a87..000000000 --- a/app/assets/javascripts/rails_startup.js +++ /dev/null @@ -1,5 +0,0 @@ -$(document).on('ready turbolinks:load', function () { - // highlight active page in the top menu - $('nav a').parents('li,ul').removeClass('active'); - $('nav a[href="' + this.location.pathname + '"]').parents('li,ul').addClass('active'); -}); diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 45b76a0f2..1ef8b0d37 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,9 +1,10 @@ class PagesController < ApplicationController + include ReactOnRails::Controller before_action :set_comments def index # NOTE: The below notes apply if you want to set the value of the props in the controller, as - # compared to he view. However, it's more convenient to use Jbuilder from the view. See + # compared to the view. However, it's more convenient to use Jbuilder from the view. See # app/views/pages/index.html.erb:20 # # <%= react_component('App', props: render(template: "/comments/index.json.jbuilder"), @@ -20,10 +21,15 @@ def index # respond_to do |format| # format.html # end + + redux_store("routerCommentsStore", props: comments_json_string) + render_html end # Declaring no_router and simple to indicate we have views for them def no_router + redux_store("commentsStore", props: comments_json_string) + render_html end def simple @@ -34,4 +40,15 @@ def simple def set_comments @comments = Comment.all.order("id DESC") end + + def comments_json_string + render_to_string(template: "/comments/index.json.jbuilder", + locals: { comments: Comment.all }, format: :json) + end + + def render_html + respond_to do |format| + format.html + end + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9e26eae84..841075b77 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -20,36 +20,16 @@ <%= csrf_meta_tags %>
- +<%= react_component "NavigationBarApp" %>