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 Rails Routes and Resources Routes to Create Actions View for New Pages

Sarah Eichenstein
Sarah Eichenstein
7,488 Points

First argument in form cannot contain nil or be empty

I followed along step by step with the teacher and for some reason I'm getting an error when I try and load the server. Even when I copy and paste the teacher's code and use that - I get the same error. This is the code:

<%= form_for(@page) do |f| %>
  <div class="field">
    <%= f.text_field :title %>
  </div>
<% end %>

I have that in /app/views/pages/new.html.erb.

Jay McGavren
Jay McGavren
Treehouse Teacher

It probably means that @page is set to nil. Something may be wrong in your controller. Can you post the code for the PagesController's new method?

2 Answers

Sarah Eichenstein
Sarah Eichenstein
7,488 Points

Oh ok. I see my mistake. I forgot to put the "def new" before the last end. Thanks for your help!

Sarah Eichenstein
Sarah Eichenstein
7,488 Points
class PagesController < ApplicationController
  def index
    @pages = Page.all
  end

  def show
    @page = Page.find(params[:id])
  end
end

def new
  @page = Page.new
end

This is the code I have in pages_controller.rb