2

I'm trying to create a page in Sinatra, so that whatever you post (under the parameter name "command") will be echoed back to you. Here's my current approach:

post '/eval' do
  "I got #{params[:data][:command]}."
end

If I try to post anything to /eval, it results in an internal server error. What am I doing wrong?

Vineel Adusumilli
  • 105
  • 1
  • 3
  • 9

1 Answers1

11

The problem is that your [:data] param is nil. One way you could fix this is to remove the reference to [:data]. Try this instead.

require "rubygems"
require "sinatra"

post '/eval' do
  "I got #{params[:command]}."
end

you can test this with curl on your command line (if you are using a unix based system).

curl http://localhost:4567/eval -F "command=hello"

In the future, It will be helpful to others if you provide a stacktrace of your error with your question.

sintaxi
  • 1,858
  • 14
  • 10