# Create db row in my partial template

**URL:** <https://www.ruby-forum.com/t/create-db-row-in-my-partial-template/142850>\
**Category:** Rails\
**Created:** [July 12, 2008, 4:00am UTC](https://www.ruby-forum.com/t/create-db-row-in-my-partial-template/142850 "2008-07-12T04:00:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 12, 2008, 4:00am UTC](https://www.ruby-forum.com/t/create-db-row-in-my-partial-template/142850/1 "2008-07-12T04:00:01Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 12, 2008, 4:55am UTC](https://www.ruby-forum.com/t/create-db-row-in-my-partial-template/142850/2 "2008-07-12T04:55:12Z")

</div>

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!’ 🙂

Fred

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 12, 2008, 5:27am UTC](https://www.ruby-forum.com/t/create-db-row-in-my-partial-template/142850/3 "2008-07-12T05:27:52Z")

</div>

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!’ 🙂
> 
> 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.

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 12, 2008, 6:01am UTC](https://www.ruby-forum.com/t/create-db-row-in-my-partial-template/142850/4 "2008-07-12T06:01:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 12, 2008, 6:28am UTC](https://www.ruby-forum.com/t/create-db-row-in-my-partial-template/142850/5 "2008-07-12T06:28:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 12, 2008, 6:40pm UTC](https://www.ruby-forum.com/t/create-db-row-in-my-partial-template/142850/6 "2008-07-12T18:40:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 12, 2008, 9:26am UTC](https://www.ruby-forum.com/t/create-db-row-in-my-partial-template/142850/7 "2008-07-12T09:26:23Z")

</div>

On Jul 12, 5:28 am, Justin To [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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
