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?

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.