Create db row in my partial template

Hi,

When I use script/generate scaffold for my db it automatically creates
that page where I can select to add a new item to the database.

In the controller, the create method looks like this:
def create
@user = User.new(params[:user])

respond_to do |format|
  if @user.save
    flash[:notice] = 'User was successfully created.'
    format.html { redirect_to(@user) }
    format.xml  { render :xml => @user, :status => :created,

:location => @user }
else
format.html { render :action => “new” }
format.xml { render :xml => @user.errors, :status =>
:unprocessable_entity }
end
end
end

And the new.html.erb looks like this:

New user

<% form_for(@user) do |f| %>
<%= f.error_messages %>

<%= f.label :email %>
<%= f.text_field :email %>

<%= f.label :password %>
<%= f.text_field :password %>

<%= f.submit "Create" %>

<% end %>

<%= link_to ‘Back’, users_path %>

I have no real clue what the new.html.erb code does. I’m trying to
replicate this form in my own template, but obviously it doesn’t work.

Can someone advise me please, thanks!

On 12 Jul 2008, at 03:00, Justin To wrote:

I have no real clue what the new.html.erb code does. I’m trying to
replicate this form in my own template, but obviously it doesn’t work.

Can someone advise me please, thanks!

What’s the question? - As far as I can tell you basically posted what
the scaffold generates, followed by ‘Help!’ :slight_smile:

Fred

Frederick C. wrote:

On 12 Jul 2008, at 03:00, Justin To wrote:

I have no real clue what the new.html.erb code does. I’m trying to
replicate this form in my own template, but obviously it doesn’t work.

Can someone advise me please, thanks!

What’s the question? - As far as I can tell you basically posted what
the scaffold generates, followed by ‘Help!’ :slight_smile:

Fred

Essentially, how do I manipulate the database outside of the class User
< ActiveRecord::Base. I need a form similar to the one that is
automatically generated via scrip/generate scaffold so I can add
additional users into my database.

I need a input fields and a submit field…

entry 1: ______ => ‘test’
entry 2: ______ => ‘test’
|submit|
=> database table Users

| entry 1 | entry 2 |


| test | test |


And… I need to validate the entries from my custom form.

Similar to the validation in the class User < ActiveRecord::Base

validates_presence_of :entry 1, :entry 2

Hope that’s clearer.

On 12 Jul 2008, at 04:27, Justin To wrote:

Can someone advise me please, thanks!
automatically generated via scrip/generate scaffold so I can add


| test | test |


And… I need to validate the entries from my custom form.

Similar to the validation in the class User < ActiveRecord::Base

validates_presence_of :entry 1, :entry 2

Sounds like you just want to edit the generated form. If you’re
running into trouble there, best post the specific issue you’re having.

Fred

I want to move the generated form from new.html.erb to my new file
add.html.erb

in partial template _user_list.html.erb:

<%= link_to_remote “+ Add User”, :url => { :action => :add_user } %>

in partial _add_user.html.erb:

<tr>
  <td>
    Password: <input type ="text" class="add-input">
  </td>
</tr>

  <tr>
    <td>
      <% form_remote_tag :url => { :action => :create } do %>
        <%= submit_tag "Add User" %>
      <% end %>
    </td>
  </tr>
Email:

in users_controller.rb:
def add_user

end

that’s all i have… I don’t know how to tie it together.

On Jul 12, 5:28 am, Justin To [email protected]
wrote:

I want to move the generated form from new.html.erb to my new file
add.html.erb

So what have you put in add.html.erb? What have you put in the
corresponding action? What happens when you visit the corresponding
url?

Fred