I am new to RoR3 am following along with the RoR3 Michael Hartl Tutorial. Out of interest, I want to move the sign-up html form to the home page rather than on a sign-up page. The code for the form:
<%= form_for(@user) do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
*** more fields ***
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
Can’t just be moved to the home page — the code won’t reference the user model properly to create a new user, and so the page doesn’t load. How does one go about accomplishing the goal of moving this form to the home page of the site?
More info: the structure of the site follows the standard rails set-up (user model named user.rb in app/models/user.rb, controller in app/users_controller.rb, views are in app/views where there are folders for pages, layouts, and users folders. The current form is in app/views/users/new.html.erb).
If the home page, for example, uses the
PagesControllerand thehomeaction, and the route isroot :to => "pages#home"or something similar, you need to instantiate the@uservariable in thehomeaction:When the form is rendered on the home page, it will have access to the
@uservariable.