Jay Killeen

Joined

4,220 Experience
26 Lessons Completed
0 Questions Solved

Activity

Posted in Ideas for building a Wiki in my app

The gist can be found at https://gist.github.com/jaykilleen/b09eb78b85e083368cb5.

I pretty much dumped most of my code relating to the wiki pages here except for the logic around users etc and a few other things. If you have any ideas to improve the code please let me know. I can do with a lot of drying up but it works. I'm lacking in time due to some other features I need to get out so if I improve it I'll update the gist.

Hope it helps someone to get some inspiration. I pretty much went from the irwi gem as the starting point with the migration and then free styled it from that point.

Posted in Ideas for building a Wiki in my app

Ill do a gist

Posted in Ideas for building a Wiki in my app

So happy!! Just shipped my wiki feature which included the ability for me to create pages, edit them as super admin, includes markup, a sidebar panel for quick navigation and I even hooked up Wistia so that I could embed some training videos I had into my wiki!

Also used the existing comments feature from your comments video and made it so users can comment on each wiki post! So freakin' awesome!!

Did I mention I wrapped some Rspec round all this. Still not doing full TDD but happy that it is not breaking without me knowing :smiley:

Posted in Ideas for building a Wiki in my app

Oh damn that is exactly what I need! I have a polymorphic comments feature that doesn't do the line breaks and things. Thanks Team Gorails!

If I keep learning at the rate I am going then I might have a crack at one of those gems. I have a few use cases for a really easy to build wiki app. I'll let you know how I get on.

Posted in Ideas for building a Wiki in my app

Oh and Chris, how did you get it so users can comment using Markdown? That would be a cool video.

Posted in Ideas for building a Wiki in my app

My users are all internal customers of our business. They are pretty information poor when it comes to our systems and processes and our company intranet is not very feature rich. So I'd like to build a wiki style feature inside my app so if they get to something they don't know about they can click help links etc and read about certain business logic etc.

I have seen https://github.com/alno/irwi which doesn't support Rails 4 and also https://github.com/nirnanaaa/gollum_rails which is no longer being supported so it doesn't seem like there is a Rails plugin style Gem to extend the functionality of your existing Rails app.

Anyone have any other ideas on where a good Gem might be?

Otherwise I am going to lookinto irwi a little more and just extract those features into my app. Maybe even one day fork it or build my first open source gem for rails that gives this functionality to your Rails app :) Probably won't happen though haha. Can only dream.

Worse comes to worse I'll just build a static page in the app and manually link it all together.

Posted in Non Restful actions in the controller

Okie dokie, so I thought long and hard about this one and have come up with a pattern that suits me. I have separated out the idea into two features 'custom views' and 'dashboards'. Dashboards are more complex and I will just run these with their own controller, routes and models. 'Custom Views' is for more specific model related views that I want the users to have quick access to. So what I have done is:

I'll make the example on my customers model.

  1. Created a new route that gets hit before the customer resources (so it doesn't conflict with the customer show route).
  resources :customer_custom_views, :controller => "customers/custom_views", only: [:index, :show]
  resources :customers, only: [:index, :show, :search] do
    collection do
      match 'search' => 'customers#index', via: [:get], as: :search
    end
  end
  1. Created a controller nested inside a folder called customers -controllers --customers ---customer_views_controller.rb
class Customers::CustomViewsController < ApplicationController

  before_action :authenticate_user!
  before_action :redirect_blocked_user

  def index
    @customer_custom_views = built_custom_views
  end

  def show
    @id = params[:id]
    case @id
      when 'owned'
        @customers = policy_scope(current_user.customers).paginate(:page => params[:page])
      when 'active'
        @customers = policy_scope(Customer.active).paginate(:page => params[:page])
      when 'active_blocked'
        @customers = policy_scope(Customer.active_blocked).paginate(:page => params[:page])
    end
    direct_to_built_custom_view
  end

  private

    def built_custom_views
      built_custom_views = ['owned', 'active', 'active_blocked']
    end

    def direct_to_built_custom_view
      if built_custom_views.include?(@id)
        verify_policy_scoped
        render "show_#{@id}"
      else
        flash[:error] = 'That is not a valid custom view for customers'
        redirect_to customer_custom_views_path
      end
    end
end
  1. Created the views in a nested folder inside the customer views

    -views
    --customers
    ---custom_views
    ----index.html.erb
    ----show_active.html_erb
    ----show_active_blocked.html.erb
    ----show_owned.html.erb
    
  2. Added the links to the navbar with

<ul class="dropdown-menu" role="menu">
  <li><a href="<%= customer_custom_views_path %>">Views</a></li>
  <% if current_user.active_customers.present? %>
    <li><a href="<%= customer_custom_view_path('active') %>">My Active Customers</a></li>
  <% end %>
  <li><a href="<%= customers_path %>">Customers</a></li>
  <li><a href="<%= customer_types_path %>">Customer Types</a></li>
  <li><a href="<%= customer_areas_path %>">Customer Areas</a></li>
</ul>
  1. Created a simple index.html.erb that lists all the different custom view I have templates for (this is hardcoded at the moment so I will figure out how to create an activerecord style hash in the controller that includes the name, descriptions etc.
  <p>Please select from the list below to be directed to a range of different views that relate to customers.</p>
  <div class="table-responsive">
    <table class="table table-hover">
      <tr>
        <th>Name</th>
        <th>Description</th>
        <tr>
          <td><%= link_to 'My Assigned Customers', customer_custom_view_path('owned') %></td>
          <td>View all the customers assigned to you.</td>
        </tr>
        <tr>
          <td><%= link_to 'Active Customers', customer_custom_view_path('active') %></td>
          <td>View all the customers assigned to you or your direct reports that are flagged as active.</td>
        </tr>
        <tr>
          <td><%= link_to 'Active Blocked Customers', customer_custom_view_path('active_blocked') %></td>
          <td>View all the customers assigned to you or your direct reports that are active but blocked from purchasing.</td>
        </tr>
    </table>
  </div>
  1. And show pages for each of those reports such as
<% content_for :title, "My Active Customers" %>

<h2>My Active Customers</h2>

<p>Below are all the customers that are assigned to you or one of your direct reports. It has been filtered for active customers which means the 'flag' field on the project has been marked as 'active'. Not all your customers are active so if you want to see all the customers assigned to you then you should go to <%= link_to "Customers", customers_path %> and search there.</p>

<p>
  <strong>Customer Count</strong>
  <%= @customers.count %>
</p>

<%= render 'shared/pagination', :collection => @customers %>
<%= render "/customers/table" %>
<%= render 'shared/pagination', :collection => @customers %>

I can probably do more to dry this up or make it more dynamic but for now it allows my users to have a page they can go to that relates to that particular table and quickly see bits of information that they want to see. It was the really easy to extend this pattern to other tables like 'projects' or 'prices' etc.

Yay!

If anyone has any ideas on how to improve this please shoot me your ideas. As you can see most of this stuff is just getting a scope of the activerecord collection from the customer.rb.

  scope :active, -> { where(active: true) }
  scope :active_blocked, -> { where(active: true, status: 'Blocked') }
  scope :inactive_blocked, -> { where(active: false, status: 'Blocked') }

The Dashboards would have way more complexity like Top 10 Customers by Net Revenue would need to sum on the sales association then order, then limit, then include other tables etc etc so I will probably create a whole class/model that does all that and has its own controller and routes etc.

Posted in Refactoring with the Null Object Pattern Discussion

This is really cool. I am in a situation where I have many user roles and would love to be able to serve a navbar for each role. Yay! Thanks. Also in my views I have used the decorator pattern like `user_decorator.rb` and then made methods with a method `link_to_project` and then in that method done something like `object.project.present? ? h.link_to(object.project.name, project_path(object.project)) : ""` or, similar to your example in the video.

`comment_decorator.rb` with a method called `link_to_user` with `object.user.present? ? h.link_to(object.user.name, user_path(object.user)) : "Anonymous"`

I have done this everywhere so I might take the null object pattern to deal with the nav first then once I get familiar try and tackle all my decorator stuff.

Posted in Non Restful actions in the controller

Been looking around and it seems I may be able to do this on the index action instead of the show. Is there a way I can pass a value into the params on the index action?? So I could pass dashboard to the index action and then render a different view than the index.html.erb??

http://stackoverflow.com/a/9779820/2585189

Posted in Non Restful actions in the controller

I tried this

  def show
    if params[:id] == "dashboard"
      @projects = policy_scope(Project)
      render :dashboard
      return
    end
    authorize @project
  end

But ran into issues with my Pundit authorization before_filters (what I'd like to put is what I have written below but obviously you can't do that).

  after_filter :verify_authorized,  except: [:index, :show(params[:id] == dashboard)]
  after_filter :verify_policy_scoped, only: :index

I mean, I could do all this by making a whole new controller, route and just using the existing models and authorization but it just seems like such a simple thing to do.

Posted in Non Restful actions in the controller

I originally asked this question about building a reporting feature in my app https://gorails.com/forum/advice-on-building-a-reports-feature.

I'd like to simplify this question even further. I want to create custom views that my user can go to for certain models in my database. For example, I have a model called 'Project' and project has a veiw for index and show. So I can show a list of all the projects in the system, scoped using Pundit so the user only sees those projects they have the authority to see. The user can then click the project and go to its 'show' page. I then add a tab in my navbar called Projects which takes them to their index.

Now Projects can be assigned to individual users and a user can edit that project and mark it is 'active'. Meaning, 'I am assigned this project but I have a lot of projects so I want to mark this one as active because I am working on it'. Now the user goes away, navigates around my app, then wants to quickly click a link that takes them to their active projects.

Do I do this on the 'index' page? Do I create a new action on the controller called 'active projects' that renders to a view called 'active projects'? Can I place a scope on the model called active and then somehow make it so the index passed active as the parameter on the index? Essentially I could have heaps of these different scopes, active projects, inactive projects? I have a ransack search box that allows the user to do heaps of searches but it is difficult to use.

How would you guys implement this simple feature?

Posted in Import CSV data using RubyZip and Postgresql COP

two issues solved with this piece of code. It skips line one which is the header and appends the "\n" new line to the string.

          data.lines.map(&:chomp).each_with_index do |line, index|
            if index > 0
              line << "\n"
              raw.put_copy_data line
              counter += 1
            end
          end

Posted in Import CSV data using RubyZip and Postgresql COP

This is what the data looks like in when I am importing from csv when the command raw.put_copy_data line is run

"415906,\"BISHOP, JOEL\",9 GARCIA COURT,PEREGIAN BEACH,4573,QLD,EXTERNAL,D,230,Country,Blocked,JOEL,N,A17,407,004,464,H01,400659,001,C16,2014-08-28 00:00:00,neym,2014-03-04 00:00:00,llavejoy,4\n"

This is the same line when running from zip.

"415906,\"BISHOP, JOEL\",9 GARCIA COURT,PEREGIAN BEACH,4573,QLD,EXTERNAL,D,230,Country,Blocked,JOEL,N,A17,407,004,464,H01,400659,001,C16,2014-08-28 00:00:00,neym,2014-03-04 00:00:00,llavejoy,4"

Writing this comment helped me solve the issue!!

Posted in Populate dropdowns based on selection

Cool thanks Chris. That makes sense. Is this something that I should implement a JSON serializer for like resource json api? At the moment my app has no JSON api interface but from all the podcast listening I have been doing it should be something is should implement.

Posted in Comments With Polymorphic Associations Discussion

Can you please elaborate on this part `you leave xss/injection etc all wide open so that body may be used to by malicious users to extend reach`? I'd like to understand the security risk a little more.

Posted in Comments With Polymorphic Associations Discussion

I found some of this information useful on how to test these polymorphic comment features at https://github.com/thoughtb...

Posted in Advice on building a 'reports' feature

A simple report would be sales where the margin is less than 0. This simply hits one table and I can currently do this using the advanced search feature of Ransack (I have the add filter buttons that Ryan Bates implemented in his Railscast on Ransack).

This is well and good to use the search filters on the existing sales index and show but as soon as it becomes more complex I would like a link that the user goes to and might have different fields etc in the index. I might also like to through a graph on the page.

Another report requires a search form to be filled in to collect certain customer and product groups and then creates a scatterplot of the different customers prices for those products.

In the past I have had this done with a separate controller, view and model for each report but just get concerned as I could have any number of these different reports etc.

Posted in Advice on building a 'reports' feature

My Ruby on Rails enterprise app has a whole range of tables ranging such as customers, products, sales, warehouses, prices etc etc.

I'd like to build a whole range of different reports that users can view that slice and dice the data certain ways. I am imagining there would be a 'search' view where you select your search parameters and then a show page that returns the result.

Is this something you would setup a MVC without a database table for? Also because I could have anywhere up to a hundred of these different reports, would you try to nest the files in your rails app architecture to keep them separated from your core MVC files or would you just not give 2 hoots and let it mix in with the rest and not be OCD about it?

My other alternative is to run a single MVC with conditionals pointing to different views in the controller based on the report selected in the index.

Sometimes I feel deciding these things is the hardest bit...

Posted in Tracking Rails App Usage with Analytics

Cool. I followed this guide http://railsapps.github.io/rails-google-analytics.html and was up and running in 10 minutes.

Looked at the redis and Ahoy one's aswell but wanted something easy to configure.

Out of interest. Google analytics is only traffic information right? (time on site, what page you are on etc) There is no chance of it capturing data that is being sent (ie user details, passwords etc). Seems like a no brainer but want to be certain.

Posted in Import CSV data using RubyZip and Postgresql COP

Or ideally do this with Rspec but god I am finding that to be a steep learning curve!

logo Created with Sketch.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2022 GoRails, LLC. All rights reserved.