-
Notifications
You must be signed in to change notification settings - Fork 17
Differences between CanCan and AuthorityController
Tortue Torche edited this page Sep 28, 2013
·
1 revision
- RESTful action names are a bit different between Rails and Laravel :
-
newaction iscreate -
createaction isstore
-
- In Laravel, unlike Rails, by default
idparameter of aProductresource isproducts. Andshop_idparameter of aShopparent resource isshops. So we need to reaffect correct parameter name(s) before executing a controller action. SeeControllerAdditions::callAction(). - In PHP all properties, methods and option names are in
camelCase($myProduct->myCamelCaseMethod();), in Ruby they are insnake_case. - Some methods don't have exactly the same name:
-
Ability#alias_action=>Authority::addAlias -
Ability#can=>Authority::allow -
Ability#cannot=>Authority::deny -
Ability|Controller#can?=>Authority|Controller::can -
Ability|Controller#cannot?=>Authority|Controller::cannot -
Ability|Controller#authorize!=>Authority|Controller::authorize
-
- In Ruby (with ActiveSupport) getter, setter, bool(true/false) methods are writing like this:
class Product
# Pro tips: You can write "attr_accessor :name" instead of the two methods declarations below
def name=(value)
@name = value
end
def name
@name
end
def named?
@name.present?
end
end
my_product = Product.new
# Setter method
my_product.name = "Best movie"
# Getter method
my_product.name #=> "Best movie"
# Check if my_product is set
my_product.named? #=> true- In PHP getter, setter, bool(true/false) methods are writing like this:
<?php
class Product
{
protected $name;
public function setName($value)
{
$this->name = $value;
}
public function getName()
{
return $this->name;
}
public function isNamed()
{
return !!$this->name;
}
}
$myProduct = new Product;
// Setter method
$myProduct->setName("Best movie");
// Getter method
$myProduct->getName(); //=> "Best movie"
// Check if $myProduct is set
$myProduct->isNamed(); //=> true