ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'API'
end
now You can write as below
class CatchJsonParseErrors | |
def initialize app | |
@app = app | |
end | |
def call env | |
begin | |
@app.call(env) | |
rescue ActionDispatch::ParamsParser::ParseError => exception |
guard 'rails', :host => "127.0.0.1", :port => '35728' do | |
watch('Gemfile.lock') | |
# Rails | |
watch(%r{app/controllers/.+\.(rb)$}) | |
watch(%r{app/helpers/.+\.rb}) | |
watch(%r{app/mailers/.+\.(rb)$}) | |
watch(%r{app/models/.+\.(rb)$}) | |
watch(%r{app/serializers/.+\.(rb)$}) | |
watch(%r{app/uploaders/.+\.rb}) | |
watch(%r{app/views/.+\.(erb|haml|slim)$}) |
origin: jerodsanto Blog
Since Rails 3 you’ve been able to configure an app to handle exceptions, which you want to point right at your router. To do this, add the following to config/application.rb:
# examples of rails 4 routes concerns | |
concern :commentable do | |
resources :comments | |
end | |
concern :image_attachable do | |
resources :images, only: :index | |
end | |
resources :messages, concerns: :commentable |
The best practice is to use a database based session, which thankfully is very easy with Rails:
Project::Application.config.session_store :active_record_store
# /config/initializers/devise.rb | |
config.password_length = 8..128 | |
# user model validates | |
validate :password_complexity | |
def password_complexity | |
if password.present? and not password.match(/\A(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+\z/) | |
errors.add :password, "must include at least one lowercase letter, one uppercase letter, and one digit" | |
end | |
end |