Code Customization
https://github.com/eliotsykes/rails-security-checklisthttps://www.owasp.org/index.php/Ruby_on_Rails_Cheatsheet
https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/
rails g mailer model_mailer new_record_notification3. Generate your mailer by typing this in Terminalrails g mailer model_mailer new_record_notification4. app/mailers/model_mailer.rband change the default from email:default from: "me@MYDOMAIN.com"
def new_record_notification(record )
@record = record
mail to: "recipient@MYDOMAIN.com", subject: "Success! You did it."
end
5. app/views/model_mailer/new_ record_notification.text.erb
Hi,
A new record has been added: <%= @record.name %>
Thanks
def create
@record = Record.new
if @record.save
ModelMailer.new_record_ notification(@record).deliver
redirect_to @record
end
end
image and video validation with paperclip
validates_attachment_presence :source
validates_attachment_content_ type :source,
:content_type => ['video/mp4'],
:message => "Sorry, right now we only support MP4 video",
:if => :is_type_of_video?
validates_attachment_content_ type :source,
:content_type => ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'],
:message => "Different error message",
:if => :is_type_of_image?
has_attached_file :source
protected
def is_type_of_video?
source.content_type =~ %r(video)
end
def is_type_of_image?
source.content_type =~ %r(image)
end
Form fields Validation
validates_length_of :first_name, maximum: 30
validates_length_of :last_name, maximum: 30, message: "less than 30 if you don't mind"
validates_length_of :fax, in: 7..32, allow_nil: true
validates_length_of :phone, in: 7..32, allow_blank: true
validates_length_of :user_name, within: 6..20, too_long: 'pick a shorter name', too_short: 'pick a longer name'
validates_length_of :zip_code, minimum: 5, too_short: 'please enter at least 5 characters'
validates_length_of :smurf_leader, is: 4, message: "papa is spelled with 4 characters... don't play me."
validates_length_of :essay, minimum: 100, too_short: 'Your essay must be at least 100 words.',
tokenizer: ->(str) { str.scan(/\w+/) }
gem 'bullet', group: 'development'
gem 'brakeman', :require => false
gem 'colored'
gem 'deadweight', :require => 'deadweight/hijack/rails'
rails_best_practices .
gem "rubycritic", :require => false
def full_name
puts "Johnnie Walker"
end
alias_method :name, :full_name
down voteaccepted
|
Use the NodeSource PPA. For details look at the installation instructions. First, choose the Node.js version you need and add the sources for it:
Then install the Node.js package.
P.S.:
curl package must be installed on server for these code lines. |
If you have
nodejs already installed and want to update, then first remove current instalation and install it again using scripts above.
|