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 trial

Ruby

Amir Frederico Carneiro Faria
Amir Frederico Carneiro Faria
1,477 Points

Not showing content input area

What's wrong with this code?


<h1>Edit page: <%= @title %></h1>

<div>
<form>
    <fieldset>
        <label for="content">Content:</label>
        <textarea rows="10" columns="50" name="content" id="content"></textarea>
    </fieldset>
    <input type="submit"> 
</form>
</div>

<p> <a href ="/"> Home </a> </p>

I'm trying to display a field to edit the content but the field is not showing.

This is my wiki.rb code:


wiki.rb
require 'sinatra'
require 'uri'

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 "/" do
    erb :welcome
end

get "/new" do
    erb :new
end

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

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

post "/create" do
    save_content(params["title"], params["content"])
    redirect URI.escape("/#{params["title"]}")
end

1 Answer

Samuel Ferree
Samuel Ferree
31,722 Points

Is the content field not showing? or is the content empty?

I'm able to see the content field when I post your html to codepen.