-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add documentation on classes / models #112
Comments
That's a good idea. I would like to have some comments, like in the rails scaffold. Can you submit something? |
Don't mind taking a swing at a couple as I go through with building my app and adding as I come across. Can you give me an example of where to start for doing this @lazaronixon as well as what format you would like to see? |
I didn't make up my mind about this. But some topics to consider:
|
I will take a look this week and put some PR's up after work. |
Sorry for the delay on this. I'm both finding a lot and a little on how others do commenting for their Rails apps (most posts are excess of 10 years old). How do we feel about a brief comment explaining most of the high-level purpose/functionality with something like the following: class RegistrationsController < ApplicationController
# Skip the authentication before action for this controller
skip_before_action :authenticate
# Action to render the sign-up form
def new
@user = User.new
end
# Action to handle the sign-up form submission
def create
@user = User.new(user_params)
if @user.save
# Create a new session for the user
session_record = @user.sessions.create!
# Set a signed, permanent cookie with the session token
cookies.signed.permanent[:session_token] = { value: session_record.id, httponly: true }
# Send an email verification to the user
send_email_verification
# Redirect to the root path with a success notice
redirect_to root_path, notice: "Welcome! You have signed up successfully"
else
# Render the sign-up form again with an unprocessable entity status
render :new, status: :unprocessable_entity
end
end
private
# Strong parameters for user sign-up
def user_params
params.permit(:email, :password, :password_confirmation)
end
# Method to send an email verification to the user
def send_email_verification
UserMailer.with(user: @user).email_verification.deliver_later
end
end Example is from the registraion html template. |
Ok so taking my original example we are looking for more of the literal rails scaffold comments. class RegistrationsController < ApplicationController
skip_before_action :authenticate
# GET /sign_up
def new
@user = User.new
end
# POST /sign_up
def create
@user = User.new(user_params)
if @user.save
session_record = @user.sessions.create!
cookies.signed.permanent[:session_token] = { value: session_record.id, httponly: true }
send_email_verification
redirect_to root_path, notice: "Welcome! You have signed up successfully"
else
render :new, status: :unprocessable_entity
end
end
private
# Only allow a list of trusted parameters through.
def user_params
params.permit(:email, :password, :password_confirmation)
end
# Method to send an email verification to the user
def send_email_verification
UserMailer.with(user: @user).email_verification.deliver_later
end
end As an aside, I think it would be best I do these in batches. So, for now I'll focus on just the controllers for a first PR and once that's done I can move onto models, etc. |
It would be great to have some code-level comments to explain a bit the architecture.
For example what the purpose of certain classes. For example, why is there a Session model.
This could help to understand the chosen architecture and helps a future developer to pick this up more quickly.
The text was updated successfully, but these errors were encountered: