Reputation:
I want to compare a param extracted from a link to the list of data present in column... I am using pluck to generate a array of list(in controller) but not getting any success in comparing it
any method that I can fetch records in model and compare with param in controller or model as passing controller instances in model seems inappropriate to me Initially i am trying fetching and comparing in controller..
@abc=Group.pluck(:group_token)
what I tried to do before is defined group_fetch method in model and used it in controller to check condition but I was not able to compare param which comes frome url dynamically
def self.group_fetch
Group.find_by group_token: 'UuzsG7NMvYFzxwPDdYgLxJbF'
end
what will be the best way to fetch db column and compare it with the link param
Upvotes: 0
Views: 510
Reputation: 14900
You can use the exists?
method which pretty much does what it says.
Group.exists?(group_token: params[:token])
Upvotes: 1
Reputation: 1739
You can use include?
to check if the param is in the list. For example:
def your_method
list = Model.pluck(:attribute)
list.include?(params[:your_param])
end
Upvotes: 1