Better Rails Partial Rendering

= render(@animals)
# actionview-
def find_template(path, locals)
prefixes = path.include?(?/) ? [] : @lookup_context.prefixes
@lookup_context.find_template(path, prefixes, true, locals, @details)
  1. If path has a / in it, then prefixes will be set to an empty array and it will search all the view directories for path. E.g. if path is lions/lion, then it will find a template like app/views/lions/_lion.
  2. Otherwise, it will traverse the controller hierarchy, e.g. if you have MeanLionsController < LionsController < ApplicationController, then a path of lion would look for a _lion partial in app/views/mean_lions/, then app/views/lions/, then finally app/views/application/.



# application.rb
config.action_view.prefix_partial_path_with_controller_namespace = false

One little problem




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Clay Shentrup

Clay Shentrup

advocate of score voting and approval voting. software engineer. father. husband. american.