11175
(-- --)
July 12, 2008, 2:00am
1
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:
<h1>New user</h1>
<% form_for(@user ) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :email %><br />
<%= f.text_field :email %>
</p>
<p>
<%= f.label :password %><br />
<%= f.text_field :password %>
</p>
<p>
<%= f.submit "Create" %>
</p>
<% 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!
What's the question? - As far as I can tell you basically posted what the scaffold generates, followed by 'Help!'
Fred
11175
(-- --)
July 12, 2008, 3:27am
3
Frederick Cheung 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
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
11175
(-- --)
July 12, 2008, 4:28am
5
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
11175
(-- --)
July 12, 2008, 4:40pm
7
in partial template _user_list.html.erb:
<%= link_to_remote "+ Add User", :url => { :action => :add_user } %>
<!--<% hidden_div_if(false, :id => "add_user") do %>
<%= render(:partial => "add_user") %>
<% end %>//-->
in partial _add_user.html.erb:
<table style="margin-top:1em;">
<tr>
<td>
Email: <input type="text" class="add-input" id="email">
</td>
</tr>
<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>
</table>
in users_controller.rb:
def add_user
end
that's all i have... I don't know how to tie it together.