To get all local users
local-user-management
To add a new user
sudo adduser new_username
To get all local users
local-user-management
To add a new user
sudo adduser new_username
Checking a single attribute on a model for validity doesn’t seem to be possible in Rails. Or at least i couldn’t find a quick answer googling around or looking through the ActiveRecord code.
What I really want to do is pass a hash into valid? with the attributes i want to validate or have an attribute_valid? method. This level of granularity is often useful in AJAX heavy apps. For instance, checking for username availability and validity as the user types during username selection.
Here is a quick solution for one User model.
To access application hosted locally over the network using HTTP, we can use ngrok
Download ngrok zip file from the website into your local machine and unzip. That gives you an executable file. Navigate to the executable file, and run
ngrok http 80
# OR
./ngrok http 80
# where 80 is the port on which the web server is listening
To get the copyright year in the footer updated dynamically
© <?php
$copyYear = 2008; // Set your website start date
$curYear = date('Y'); // Keeps the second year updated
echo $copyYear . (($copyYear != $curYear) ? '-' . $curYear : '');
?> Copyright.
If you have to work with older versions of Rails, there might be discrepancy between the versions of Rails and Rubygems. You are likely see the below message when you try to boot your rails app.
/home/lt-pc-528/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.7/lib/active_support/dependencies.rb:55: uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)
You can fix the error by adding the following to environment.rb and script/server.rb files before you require boot.rb file.
class_eval is called on a class object and is used to create instance methods for the class at runtime.
%w(administrator developer teamlead tester).each do |user|
class_eval <<-EOR
def is_#{user}?
site == "MYACCOUNT_#{org.upcase}"
end
EOR
end
In Ruby, send is often introduced as a way to show how everything is an object
1.send(:+, 1) ## -> 2
It can also be used to call private or protected methods from outside a given class as explained below.
class Myclass
def method_one
In Rails programming you might seldom come across the below statement
$:.unshift File.dirname(__FILE__)
$: represents load path in Ruby. Its a pre-defined variable and short hand for $LOAD_PATH which ruby uses to look for files.
unshift prepends the given path to the beginning of the array (load path).
x ||= y is similar to x || x = y.
In the above statement, if x evaluates to logical true then assignment is not done. If x evaluates to logical false only then the assignment is done.
Though the above two statements are similar, there are subtle differences.
# if x is not defined
Note : This is as of rails 2.3.5. The methods might have been deprecated or the behavior might have changed in the latest versions of Rails.
prepend_before_filter and append_before_filter are almost the same.
They differ only in precedence. Prepend filters have higher precedence over append filters.
before_filter is an alias to append_before_filter
class MyController < ActionController::Base