Dillon Wyatt
Dillon Wyatt
4,974 Points

Error on Inspection and creation


Following along with the course we have created a form that will post the inputted data. I am following along while using my own text editor. When I run the program currently, I am getting an error I can figure out how to resolve. I would appreciate some help. I imagine it is something super simple that I am overlooking.

Relevant Ruby Code:

require "sinatra"

set :bind, ""

def page_content(title)"pages/#{title}.txt")
rescue Errno::ENOENT
  return nil

def save_content(title, content)"pages/#{title}.txt", "w") do |file|

get "/new" do
    erb :new

get "/:title" do
    @title = params[:title]
    @content = page_content(@title)
    erb :show

post "/create" do

# not currently part of the code but the next step is to replace params.inpsect with
# save_content(params["title"], ["content"])

I have managed to get the inspect to work once when I first did it. It was the transition to the next step that generated an error. I do not think I changed any other relevant code between steps that would cause an error to pop up.

Short of posting the entire page of text regarding the error, I am not sure what I should add here to help clarify the error Sinatra is giving me. The topline bit, however, is

"Errno::EINVAL at /create Invalid argument @ io_writev - <STDERR> file: base.rb location: write line:1161"

Looking at the backtrace for line 1161, I get the following:

"C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb in write @env['rack.errors'].puts(msg) C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb in puts @env['rack.errors'].puts(msg) C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb in dump_errors! @env['rack.errors'].puts(msg)"

Anyone have any clue what I am doing wrong here?

1 Answer

Dillon Wyatt
Dillon Wyatt
4,974 Points

I haven't the faintest clue why, but I found out what was causing the bug. The Set :bind, "0,0,0,0" up at the top was the cause. I have run the samw code with and without it and that is the sticking point. Once removed, the code runs as it should.

Can anyone explain why that bit would kick up an error?