1

Sinatra で応答を返そうとすると、NoMethodError が発生しました。これはエラーです:

/contact/book-me.php の NoMethodError

未定義のメソッド `body=' for #<String:0x00000001911418>

/home/kerrick/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.2/lib/sinatra/base.rb in body
        response.body = value
/home/kerrick/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.2/lib/sinatra/base.rb in invoke
        body res
/home/kerrick/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.2/lib/sinatra/base.rb in call!
      invoke { dispatch! }
/home/kerrick/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.2/lib/sinatra/base.rb in call
      dup.call!(env)
/home/kerrick/.rvm/gems/ruby-1.9.3-p194/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb in call
        status, headers, body = @app.call(env)
[...]

これは関連するコードです:

# Snipped, but basically populate the @error hash if the form wasn't filled out right
if @error.length == 0
  #Snipped, but basically handle the success case
else
  @response = ''
  @error.each do |x, y|
    @response << "<li>#{y}</li> \n"
  end
  return [400, @response]
end

なぜこうなった?

4

1 に答える 1

1

Sinatra で戻り値として使用@responseすると、問題が発生します。同じ問題がRuby on Rails OldWikiで文書化されているため、Sinatra だけの問題ではありません。コードを次のように変更する必要があります。

else
  @send_errors = ''
  @error.each do |x, y|
    @send_errors << "<li>#{y}</li> \n"
  end
  return [400, @send_errors]
end
于 2012-06-01T15:06:19.117 に答える