FEATURE: Can edit category/host relationships for embedding#1
FEATURE: Can edit category/host relationships for embedding#1akshayutture-augment wants to merge 1 commit into
Conversation
| end | ||
|
|
||
| def update | ||
| host = EmbeddableHost.where(id: params[:id]).first |
There was a problem hiding this comment.
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.
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.
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.
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.