perhaps someone can take a little time to give me a better
understanding of how to use form helpers.
Here is what I’m working with in my app:
user model - (the table where a user registers their information)
it contains the following fields -
first_name
last_name
email
account_type (currently set to string but will probably be a select
box with options)
password_salt (I’m assuming these would be hidden)
password_hash ( " )
controller main / welcome
def welcome
end
For now all welcome does is pull up the main/welcome.rhtml page
In welcome.rhtml all I have is one line:
<%= render :partial => “user/register” %>
but there is also a main.rhtml layout so welcome.rhtml is embedded in
one of the main layout divs.
Last is the user/register partial:
currently in which i have this code. I know I want to drop this in
favor of form helpers for various reasons, one being styling.
<%= form_tag :controller => “main”,
:action => “register” %>
<%= labeled_text_field “First name”, :user, :first_name %>
<%= labeled_text_field “Last name”, :user, :last_name %>
<%= labeled_text_field “Email”, :user, :email %>
<%= labeled_text_field “Account Type”, :user, :account_type %>
<%= labeled_text_field “Password”, :user, :password %>
<%= end_form_tag %>
My confusion is in a few areas. I’m not sure what I need in the
controller. Right now the user controller has this one method:
def register
c = User.new(params[:user])
c.save
redirect_to :controller => “main”
end
I think this is correct and the right controller for it to be in since
it relates to the user model / object.
Secondly do I use the form helpers in user_helper or main_helper. I
have some attempt at a form helper in main_helper currently. In the
user controller I have helper :main, but maybe I should just keep the
form helpers in user_helper ?
Lastly after I get whatever it is I need in the helper file, what is
it that I put in the view to call it ?
Sorry, I’m having a hard time getting this to sink in.
Stuart