Skip to content

Commit

Permalink
Fix search list, optional and attr
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleylhs committed Jul 17, 2024
1 parent ff253d3 commit 37fc2a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions app/controllers/lists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ class ListsController < ApplicationController
# POST /lists
#----------------------------------------------------------------------------
def create
list_params[:user_id] = (current_user.id if params[:is_global].to_i.zero?)

list_attr = list_params.to_h
list_attr[:user_id] = (current_user.id if params[:is_global].to_i.zero?)
# Find any existing list with the same name (case insensitive)
if @list = List.where("lower(name) = ?", list_params[:name].downcase).where(user_id: list_params[:user_id]).first
@list.update(list_params)

if @list = List.where("lower(name) = ?", list_attr[:name].downcase).where(user_id: list_attr[:user_id]).first
@list.update(list_attr)
else
@list = List.create(list_params)
@list = List.create(list_attr)
end

respond_with(@list)
Expand Down
2 changes: 1 addition & 1 deletion app/models/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class List < ActiveRecord::Base
validates_presence_of :name
validates_presence_of :url
belongs_to :user
belongs_to :user, optional: true

# Parses the controller from the url
def controller
Expand Down

0 comments on commit 37fc2a5

Please sign in to comment.