0
我一直在收到这个错误,没有将Symbol隐式转换为Integer。我搜索了这个错误,但并没有真正理解它。代码在底部。一旦它到达这个“if q [:text_field] .is?Array”,那就是当它给出错误时,我确信该代码的其余部分是错误的。但不知道如何解决它。没有将Symbol隐式转换为Integer,rails 4
pages = Vovici::API.new(@pid).survey_structure
这是我用上面的代码调用的api数据的示例。
[{:q_fill_in=>
{:heading=>{:text=>"1"},
:instructions=>{:text=>nil},
:body=>{:text=>"Pac"},
:list_caption=>{:text=>{:@type=>"plain"}},
:total_label=>{:text=>"Total"},
:text_field=>
[{:label=>{:text=>"first"},
:preselection=>{:text=>{:@type=>"plain"}},
:symbol=>{:text=>{:@type=>"plain"}},
:@id=>"1",
:@dbheading=>"Q1_1",
:@row=>"0",
:@size=>"20",
:@xmltype=>"text",
:@required=>"false",
:@compare_expression=>"-1",
:@topic_first=>"true",
:@slider=>"false",
:@sliderstep=>"1",
:@published=>"true",
:@usecalendarpopup=>"true",
:@insert_symbol_left=>"false",
:@label_width=>"3",
:@text_area_width=>"9"},
{:label=>{:text=>"id"},
:preselection=>{:text=>{:@type=>"plain"}},
:symbol=>{:text=>{:@type=>"plain"}},
:@id=>"2",
:@dbheading=>"Q1_2",
:@row=>"0",
:@size=>"20",
:@xmltype=>"text",
:@required=>"false",
:@compare_expression=>"-1",
:@topic_first=>"true",
:@slider=>"false",
:@sliderstep=>"1",
:@published=>"true",
:@usecalendarpopup=>"true",
:@insert_symbol_left=>"false",
:@label_width=>"3",
:@text_area_width=>"9"}],
:@dbheading=>"Q1"}
这是代码从我的RB文件
def process
pages = Vovici::API.new(@pid).survey_structure
pages.each do |page|
if page[:q_fill_in]
process_fill_in(*page[:q_fill_in])
end
end
end
def process_fill_in(*questions)
questions.each do |q|
if q[:text_field].is? Array
sub_qs = q[:text_field]
else
sub_qs = [q[:text_field]]
end
q_text = clean_question_text(q[:body][:text])
sub_qs.each do |sq|
sub_text = clean_question_text(sq[:label][:text])
q_name = [q_text, sub_text.reject { |i| i.nil? || i.empty? }.join("--")]
@survey.questions.create!(qheader: sq[:@dbheading], qtext: q_name)
end
end
end
def clean_question_text(text)
match = /( )?(<.*?>)?(.+)( )?(<\/.*>)?/.match(text)
match[3]
end
任何人都可以请帮助?
我这样做是因为从api数据中看到了一组哈希值,但显然这是错误的。你有什么建议,我可以做些什么来解决它。 –
据我可以告诉你根本不需要该图示(也可能不在process_fill_in中)。 –