[Past POST] I will publish a part of the answer memo when I was a mentor of TECH :: CAMP

Past POST

I will publish what I wrote down when I was a mentor for TECH :: CAMP in the past. I tried to divide it into small pieces, but I will summarize the small ones. My memory is ambiguous, so there may be some mistakes ...

Q. I can't retrieve the contents of the hash

movie = {"title" => "Harry Potter", "genre" => "fantasy", "year" => "2001"} Write the code that takes the string you want to get from. I think it was a problem like this.

Corresponding code


def movie_info(movie, data)
  puts movie[data]
end

movie = {"title" => "Harry potter", "genre" => "Fantasy", "year" => "2001"}

puts "Please select one from the following and enter it.
・ Title
・ Genre
・ Year"

info = gets.chomp

movie_info(movie, info)

Commentary

here puts movie[:data] If you do, it will not work. The reason is that the type is different.

info = gets.chomp Since we are receiving the key as a "string" here The hash definition also uses the string "title", so there is no problem here.

puts movie[:data] On the other hand, if you write it like this, it will be output as a symbol type, Nothing is output because the type is different.

By the way, you can check the type by using .class. ex) info.class

If you want to use symbol type movie = {title: =>" Harry Potter "} Change the hash definition like info = gets.chomp.to_sym If you rewrite it like this, it will work.

puts movie[data.to_sym] But it's okay. (Converted to symbol type)

Q.devise, no method error When no method error occurs related to devise. For example, there is no current_sign_in_at.

Workaround

Check the corresponding migration file created by devise Remove the comment out around the relevant part Recreate the database $ rake db:migrate:reset You can do it all at once with this command.

This command drops the database once, It is a command to recreate the database based on the existing migrate file. Of course, the data in the database will be erased. If you want to keep various data, I think you should output the data in CSV and save it somewhere.

If you migrated just before, you may roll back.

$ rake db:migrate:status

You can check which files are currently migrated with.

Cause

When I installed the device, I left the items commented out by default. The method you want to use was not generated. It should be solved by redoing the migration again.

On Q.heroku, ids are given in increments of 10.

There is no problem in the development environment, but it changes only in the production environment. I don't think many people care about it, but this is the default setting for clearDB. It seems that heroku uses cleardb as the db server.

【reference】 http://w2.cleardb.net/faqs/#general_16 When I use auto_increment keys (or sequences) in my database, they increment by 10 with varying offsets. Why? ClearDB uses circular replication to provide master-master MySQL support. As such, certain things such as auto_increment keys (or sequences) must be configured in order for one master not to use the same key as the other, in all cases. We do this by configuring MySQL to skip certain keys, and by enforcing MySQL to use a specific offset for each key used. The reason why we use a value of 10 instead of 2 is for future development.

Recommended Posts

[Past POST] I will publish a part of the answer memo when I was a mentor of TECH :: CAMP
A memo when you want to clear the time part of the calendar
I made a gem to post the text of org-mode to qiita
A memo that was soberly addicted to the request of multipart / form-data
A story I was addicted to when testing the API using MockMVC
[CircleCI] I was addicted to the automatic test of CircleCI (rails + mysql) [Memo]
I was stuck with the handling of the time zone when formatting with SimpleDateFormat
What I tried when I wanted to get all the fields of a bean
I managed to get a blank when I brought the contents of Beans to the textarea