-
Notifications
You must be signed in to change notification settings - Fork 0
FEATURE: Can edit category/host relationships for embedding #1
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
base: rest-serializer-enhancement-pre
Are you sure you want to change the base?
FEATURE: Can edit category/host relationships for embedding #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review completed. 4 suggestions posted.
Comment augment review to trigger a new review at any time.
| end | ||
|
|
||
| def update | ||
| host = EmbeddableHost.where(id: params[:id]).first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
host can be nil here if an invalid id is passed; consider handling the not-found case (e.g., 404) to avoid a 500 from save_host.
🤖 Was this useful? React with 👍 or 👎
| end | ||
|
|
||
| def destroy | ||
| host = EmbeddableHost.where(id: params[:id]).first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as update: if host is nil, host.destroy will raise; consider returning a 404 or similar when the record isn’t found. (Related to the update action above.)
🤖 Was this useful? React with 👍 or 👎
| belongs_to :category | ||
|
|
||
| before_validation do | ||
| self.host.sub!(/^https?:\/\//, '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.host.sub! will raise if host is nil; guarding for presence before normalizing (or defaulting to an empty string) will prevent validation-time exceptions.
🤖 Was this useful? React with 👍 or 👎
| host = uri.host | ||
| return false unless host.present? | ||
|
|
||
| where("lower(host) = ?", host).first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query uses lower(host) = ? but doesn’t lowercase the bound value; using host.downcase (or lower(?)) avoids case-mismatch issues for mixed-case hosts.
🤖 Was this useful? React with 👍 or 👎
No description provided.