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 trialLisa Rossiter
3,630 Pointshow do I move a form
I would like to move a form onto another page such as new status on the status page how would I do this?
I have tried but it just comes up with errors.
10 Answers
Lisa Rossiter
3,630 PointsGot it!
I had to add the method to the controller
def index
@statuses = Status.all
@status = Status.new
end
Michael Williams
8,074 PointsHey Lisa,
If you post your code I should be able to help you. I just need more info on what you are trying to do. :)
Lisa Rossiter
3,630 PointsOk so as an example the below is index.html.erb which prints out my statuses. I want the new status form to be on this page through a partial.
<%= render 'new_status' %>
<% @statuses.each do |status| %>
But I would also like to move the devise sign up form onto my homepage. Would I for the devise new registration form do a route:
root to: "devise/registrations#new"
and code my website homepage into that view. This might be covered later on in the tutorial but I was just wondering.
Michael Williams
8,074 PointsSo if you are trying to make "devise/registrations#new" your root you would just do root 'devise/registrations#new' in 'config.routes.rb'. For the partial you need to put it into a _form.html.erb file in your layouts folder then render 'form' on the root page.
I hope that makes sense :) Let me know if that doesn't answer the question!
Lisa Rossiter
3,630 PointsNot quite I get this error if I include a partial in the index.html.erb
undefined method `model_name' for NilClass:Class
Michael Williams
8,074 PointsDid you change your routes.rb file to:
root 'devise/registrations#new'
then create a '_form.html.erb' in layouts folder
and add the form code in the 'form.html.erb'? like
<%= form_for(@example) do |f| %> . . . <% end %>
if you have and that isn't working post the full error message and what you have done.
Lisa Rossiter
3,630 PointsIf we start again. I want to first add the new status form into index.html.erb the page that outputs statuses. Forget about devise for now.
<%= render 'form' %>
<% @statuses.each do |status| %>
My route has only this in it
root to: "statuses#index"
It is outputting the following error.
undefined method `model_name' for NilClass:Class
This comment form doesn't allow me to upload files. Really appreciate your help.
Michael Williams
8,074 PointsHmmm.... It looks like your <%= render 'form' %> is correct. I don't know why it would be throwing an undefined method error. Do you have a git hub account? I could look at your whole code on there.
Michael Williams
8,074 PointsSweet.
Michael Williams
8,074 PointsWait, you didn't put @status = Status.new in your index did you?
Lisa Rossiter
3,630 PointsNo in the status controller?
Thanks for your help Micheal