#lucky
In Rails you have controllers, and controllers have actions. In Lucky, we just have “Actions.” Another different is that Lucky handles routing in the action instead of in a different routes file
What’s different?
- Instead of a controller class with methods for actions, Lucky just has “actions” that are single classes. E.g. (
UsersController#index
in Rails isUsers::Index
in Lucky) - Lucky defines routes in the action, not in a separate routes file
- Lucky can infer RESTful routes and namespaces for you
# config/routes.rb
resources :users, only: :index
# app/controllers/users_controller.rb
class UsersController < ApplicationController
def index
end
end
What’s different?
What’s different?
- Lucky requires you to tell it what to render.
- Lucky requires the render to be returned at the end of the action
- Instance variables are rarely used in Lucky actions, and are not automatically passed to the view
For HTML:
# src/actions/users/index.cr
class Users::Index < BrowserAction
route do
render IndexPage, name: "Paul"
end
end
Rails:
class User < ApplicationRecord
validates :name, presence: true
validate :custom_validate, if: :custom_method?
end
Lucky:
class UserForm < User::BaseForm
def prepare
custom_validation if custom_method?
end
end
In-depth guide: Screencasts: