Home>
As the title says, I want to output the array in the yml file to the view with rails.
Specifically, I want to output the contents line by line according to the number of elements in the array.
undefined method `each'for #<String: 0x000000>
Corresponding source code
I'm writing in slim
--hoge (hoge_entities, identity [: foo_codes]). each do | foo |
--if foo [: bar] .present?
--foo [: bar] .each do | bar |
span = bar
I get an error here.
# =>undefined method `each'for #<String: 0x000000>
def foo
setting_yml [: bar]
end
foo:
bar: bar:
--Hello1
--Hello2
What I tried
Please describe here what you have tried for the problem.
When I wrote the rails part of the corresponding source code, it became undefined method'each'. Try it on the console
pry (main)>foo = Foo.find (1)
# =>id: 1, name: "Foo", created_at: xxx, updated_at: xxx
pry (main)>foo [: bar] .each do | bar |
pry (main) * puts bar
pry (main) * end
# =>Hello1
# =>Hello2
I was able to output, so I do not understand why slim fails.
By the way, with slim
--hoge (hoge_entities, identity [: foo_codes]). each do | foo |
--if foo [: bar] .present?
span = foo.bar
If it is, it will be output correctly.
This is a rudimentary question, but I would appreciate it if you could answer it! !!
-
Answer # 1
Related articles
- ruby - i want to output csv with narrowed down conditions with rails
- ruby on rails - image cannot be saved (activestorage installed) null in image of table
- ruby on rails - i don't understand the content of the error
- [ruby on rails] i want to implement a follow function, but the like button is not displayed in the view
- ruby - i want to collect the same records using rails group and get the value
- ruby on rails 6 - i want to save data from one form to multiple tables at the same time
- ruby on rails - s3 images are not saved on the ec2 server
- ruby - i want to fix the number of elements in the array and fill the missing elements with 0 from the end
- ruby on rails - i'm having trouble getting an actionview :: syntaxerror while implementing category selection using active_hash
- ruby - i'm having trouble with rails nomethoderror (i want to get data with each method!)
- ruby on rails - api key is not read by dotenv-rails
- ruby on rails - about conditional branching using elsif
- ruby on rails 5 - child model record not created
- ruby on rails - about multi-word search to multiple columns using ransack
- ruby on rails - the latitude and longitude of the registered address is not converted by geocoding
- ruby on rails - how to remove some child elements from an already generated model in a rails has_many relationship
- ruby on rails - when a photo is added to a folder on the pc, i want to display it on the browser of the web application!
- ruby - if you try to add a gem to the rails gemfile, everything below the added code will change to meaningless code
- ruby - i can't do rails s well ,
Related questions
- ruby - passing variables using render partial
- ruby - deployment error on heroku
- ruby - output the total integer value held by each user
- ruby - i want to use the search method for active hash data
- ruby - destroy action does not respond
- ruby - how do you see the rails controller relative path? (carrierwave directory deleted)
- ruby - when deploying on capistrano, i get the error "access denied for user'ec2-user' @'localhost' (using password: no)&qu
- javascript - run multiple times with js + each do
- how to reflect the layout downloaded from the external site in ruby on rails?
- ruby - how nice! function routes do not pass well (relation) [rails]
This has been resolved. ..
Specifically, three yml files are output in one slim file, and each of the three yml files
foo: bar
The data was included, and two of the yml files were not in the form of an array as described above, so an error occurred.
So each yml file has no relation to the number of elements
And, by raising it in the form of an array, each error disappeared.