No commit activity in last 3 years
No release in over 3 years
provide a way to DRY shared/common Rails views
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
>= 0
>= 0
~> 10.0
 Project Readme

Gem Version

RailsPatternView

Ever annoyed with having to copy/paste the Rails views around for very common pages, this gem will solve it Creaet your view folder (pattern) once and instruct your controller to use that pattern

Installation

Add this line to your application's Gemfile:

gem 'rails_pattern_view'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rails_pattern_view

Usage

class CatsController < ApplicationController
  use_pattern :ajax_table

  def new; end
  def edit; end
end

class DogsController < ApplicationController
  use_pattern :ajax_table, only: [:new]

  def new; end
  def edit; end
end

Add this in your views

views/shared/patterns/ajax_table/new.erb
views/shared/patterns/ajax_table/edit.erb
views/dogs/edit.erb

Both CatsController & DogsController now can share the views within ajax_table

Options

only

use_pattern :ajax_table, only: [:create, :update, :destroy]

except

user_pattern :ajax_table, except: [:new]

mapping

use_pattern :ajax_table, mapping: {:refresh_table => [:create, :update, :destroy]}

all "create/update/destroy" actions will now render "views/shared/patterns/ajax_table/refresh_table"

template

use_pattern :ajax_table, only: [:create, :update, :destroy], template: 'refresh_table'

Notes:

only & except can't be mixed

mapping & template can't be mixed

Development

Run specs with rspec spec

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/nqtien310/rails_pattern_view. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.