Я пытаюсь создать форму rails с помощью и тегом, но я хочу сгенерировать опции с помощью json-файла, потому что я хочу всех стран. Но у меня есть эта ошибка:Ruby on rails: undefined method 'map' для # <String>
undefined method `map' for #<String:0x007f871472e9b0>
Вот мой application_helper.rb:
module ApplicationHelper
def countries_for_select
file = File.read(File.join(Rails.root, 'app', 'helpers', 'countries.json')).to_json
countries = JSON.parse(file)
countries.map {|c| [ c['country']['name'], v['country']['code'] ] }
end
end
Вот мой posts_controller.rb:
def create
countries_for_select
@post = Post.new(posts_params)
@post.user = current_user
options_for_countries
if @post.save
flash[:success] = "Your post have been published"
redirect_to post_show_path
else
render 'new'
end
end
Вот строка в моей _form. html.erb файл:
<%= select_tag(:country, countries_for_select) %>
Так что я не понимаю, почему это не работает, Помогает ли кто-нибудь мне?
Спасибо!
Я бы подробно остановился на этом. –
@SergioTulentsev мой английский или что-нибудь еще? –
Это лучше :) –