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!
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung 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!'' :-) > > FredEssentially, 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12 Jul 2008, at 04:27, Justin To wrote:> > Frederick Cheung 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 2Sounds 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I want to move the generated form from new.html.erb to my new file add.html.erb -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 12, 5:28 am, Justin To <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I want to move the generated form from new.html.erb to my new file > add.html.erbSo 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---