class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors[attribute] << (options[:message] || "must be a valid URL") unless url_valid?(value)
end
# a URL may be technically well-formed but may
# not actually be valid, so this checks for both.
def url_valid?(url)
url = URI.parse(url) rescue falseRails Admin field configuration
rails_admin do
list do
field :customfield do
def value
bindings[:object].your_method
end
end
endIn your logged_in_controller.rb
class LoggedInController < ApplicationController
before_filter :authenticate_user!
endIn your logged_in_controller_spec.rb
User.where(:role => :admin).order(:username).pluck(:email) #=> [admin1@example.com, admin2@example.com]Heroku Mailer (SendGrid) configuration steps
-
Go to your heroku application.
-
Add SendGrid addons
-
Config STMP settings to your config/environment.rb
ActionMailer::Base.smtp_settings = {get gemset list
rvm gemset listempty gemset
rvm getmset empty [gemset_name]= simple_form_for @time_slot, url: booking_path, method: :patch do |f|
= f.input :start_time, :as => :datetime, :minute_step => 30, :include_seconds => true, :discard_year => true, :datetime_separator => ' — ', :time_separator => ' - '
= f.input :id, as: :hidden
= f.submit "Book this slot", class: 'btn'Setup a WYSIWYG editor with CKEditor. Includes instruction for Rails_Admin
- Add
gem 'ckeditor'to your Gemfile and bundle - Checkout https://github.com/galetahub/ckeditor for instruction to generate the correct model to generate for uploading of files (eg. ActiveRecord + Paperclip)
- Run
rake db:migrate - Add
//= require ckeditor/overridein your application.js (before require_tree .)
To configure the editor to be used in Rails_Admin, follow this https://github.com/sferik/rails_admin/wiki/CKEditor
- Star Rating with only CSS
<div class="star-wrapper">
<a class="star" href="javascript:alert(1)"></a>
<div class="star-wrapper">
<a class="star"></a>
<div class="star-wrapper">
<a class="star"></a>
<div class="star-wrapper">