Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDillon Wyatt
5,990 PointsError on Inspection and creation
Hello,
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, "0.0.0.0"
def page_content(title)
File.read("pages/#{title}.txt")
rescue Errno::ENOENT
return nil
end
def save_content(title, content)
File.open("pages/#{title}.txt", "w") do |file|
file.print(content)
end
end
get "/new" do
erb :new
end
get "/:title" do
@title = params[:title]
@content = page_content(@title)
erb :show
end
post "/create" do
params.inspect
end
# 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
5,990 PointsI 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?