Ruby/Rails update model attribute with array items? [closed] - ruby-on-rails

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to populate column_name with items from #enc. Problem is #update_all updates all fields with last item in array?
Last item is "MPq3KSzDzLvTeYh+h00HD+5FAgKoNksykJhzROVZWbIJ36WNoBgkSoicJ5wx\nog0g\n".
I am trying to populate with all items from array not just last.
I hope question is clear?
I tried #update_attributes, but no success?
Help.
Thanks
#enc=["hUt7ocoih//kFpgEizBowBAdxqqbGV1jkKVipVJwJnPGoPtTN16ZAJvW9tsi\n3inn\n", "wGNyaoEZ09jSg+/IclWFGAXzwz5lXLxJTUKqCFIiOy3ZXRgdwFUsNf/75R2V\nZm83\n", "MPq3KSzDzLvTeYh+h00HD+5FAgKoNksykJhzROVZWbIJ36WNoBgkSoicJ5wx\nog0g\n"]
#enc.each do |i|
PaymentMethod.update_all(enc_number: i)
end

PaymentMethod.all.each_with_index do |payment, n = 0|
payment.update_column(:enc_number, #enc[n])
n +=1
end

Related

Ruby and Rail - How to combine date and time to get data [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
Currently, I have 3 columns : booking_date, booking_time_from, booking_time_to.
Problem is how can i get all data have booking time 2 hours ago using Active Support ?
Booking.where([booking_time], 2.hours.ago.to_datetime)
I'm not sure about what's the difference between booking_time_from and booking_time_to, and which column that the booking time you're referring here. Let's assume it's booking_time_to, you can
Booking.where("booking_time_to < ?", 2.hours.ago)

How do I separate out fields in a CKRecords results Xcode objective-c [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have saved data to fields in CloudKit and I have queried for the posts by date in decending order and by getting the one at index(0) I have the last post. My question is how do I separate out the various fields and use them to populate the text in various labels in my view. Here is what I have for the latest post query.
<CKRecord: 0x104e5b600; recordID=157F08E2-FF00-42DD-8B89-7CB10FAC81B6:(_defaultZone:__defaultOwner__), recordChangeTag=kk6d3s69, values={ temperature=54, trip=50, level=53, battery=64, date=1-20-2021 20:57:09 }, recordType=MyPoolInfo>
If someone could help me out I would appreciate it. Thanks
I figured this out. This is a dictionary. So I just called the following:
NSLog(#"temperature:%#",[dictionary objectForKey:#"temperature"]) ;
NSLog(#"date:%#",[dictionary objectForKey:#"date"]) ;
NSLog(#"trip:%#",[dictionary objectForKey:#"trip"]) ;
NSLog(#"battery:%#",[dictionary objectForKey:#"battery"]) ;
NSLog(#"level:%#",[dictionary objectForKey:#"level"]) ;
I could then fill in the label.text like this:
self.DateLabel.text =[dictionary objectForKey:#"date"];
in case anyone needs to know.

How to add a number to a current value in rails? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Sorry for my English. I have a model with some field.
How to add a number to a current value in field?
I want to add the number several times
i generated scaffold.I use this to create modal. But i want to add number to a current value when i clicked submit
#foo = Foo.first
#foo.bar += 10
#which is a shorter way of saying #foo.bar = #foo.bar + 10
#foo.save
If this isn't helpful, please add some more details to your question, eg your example code you have so far.

Ruby sort an array in ascending order [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have an array ['f_1', 'f_10', 'f_3', 'f_2']
I want to sort this array in ascending order using ruby one line code.
Do as below using sort_by :
['f_1', 'f_10', 'f_3', 'f_2'].sort_by { |s| s[/\d+/].to_i }
# => ["f_1", "f_2", "f_3", "f_10"]

How to insert into a value an HTML insert [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to do a simple login form that just compare the value that you insert into the input in HTML to the data you had in the database. How can I do it?
Setup a controller and compare the params hash.
expected_value = '...'
if params[:form_value] == expected_value
do_something()
else
do_something_else()
end

Resources