Chris Johnston
2007-Jun-07 02:06 UTC
Any tutorials on how to do multiple row (data grid like) form?
Hello, I am trying to create a multiple row / data grid like input form and am not sure how to proceed. I am wondering if there are any good tutorials on how to do something like this. To be more exact in what I am trying to do, imagine it is an expense report application in which a user has to enter the expense amount, a description, and select the category under which the expense belongs. The form consists of 5 rows, each row consisting of a field to enter each piece of information for a single expense. The form would also offer the user the chance to add or subject rows. I am looking for a tutorial that covers both the view and controller side of doing this as I am fairly new to Rails. Thank you for you help with this. Chris Johnston -- www.fuzzylizard.com You know you''ve achieved perfection in design, Not when you have nothing more to add, But when you have nothing more to take away. -- Antoine de Saint-Exupery --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
tmac
2007-Jun-07 03:18 UTC
Re: Any tutorials on how to do multiple row (data grid like) form?
I think you may be looking for something like this:
<% form_for :expenses do |form| %>
<% @expenses.each_with_index do |expense, index| %>
<%= form.text_field(:amount, :index => index) %>
<%= form.text_field(:description, :index => index) %>
<% end %>
<% submit_tag %>
<% end %>
then in the controller you should be able to access the data as a hash
of hashes:
params[:expenses].keys.each do |index|
Expense.create(params[:expenses][index])
end
or however you want to handle that.
None of that is tested but I >think< that is the general idea.
Hope that helps!
Tim
On Jun 6, 7:06 pm, "Chris Johnston"
<fuzzyliz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hello,
>
> I am trying to create a multiple row / data grid like input form and am not
> sure how to proceed. I am wondering if there are any good tutorials on how
> to do something like this.
>
> To be more exact in what I am trying to do, imagine it is an expense report
> application in which a user has to enter the expense amount, a description,
> and select the category under which the expense belongs. The form consists
> of 5 rows, each row consisting of a field to enter each piece of
information
> for a single expense. The form would also offer the user the chance to add
> or subject rows.
>
> I am looking for a tutorial that covers both the view and controller side
of
> doing this as I am fairly new to Rails.
>
> Thank you for you help with this.
>
> Chris Johnston
>
> --www.fuzzylizard.com
>
> You know you''ve achieved perfection in design, Not when you have
nothing
> more to add, But when you have nothing more to take away.
> - Antoine de Saint-Exupery
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Chris Johnston
2007-Jun-07 04:05 UTC
Re: Any tutorials on how to do multiple row (data grid like) form?
Cool, from reading through it, it looks like might just do it. Thanks. Chris On 6/6/07, tmac <mcintyre.tim-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I think you may be looking for something like this: > > <% form_for :expenses do |form| %> > <% @expenses.each_with_index do |expense, index| %> > <%= form.text_field(:amount, :index => index) %> > <%= form.text_field(:description, :index => index) %> > <% end %> > <% submit_tag %> > <% end %> > > then in the controller you should be able to access the data as a hash > of hashes: > > params[:expenses].keys.each do |index| > Expense.create(params[:expenses][index]) > end > > or however you want to handle that. > > None of that is tested but I >think< that is the general idea. > > Hope that helps! > Tim > > On Jun 6, 7:06 pm, "Chris Johnston" <fuzzyliz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hello, > > > > I am trying to create a multiple row / data grid like input form and am > not > > sure how to proceed. I am wondering if there are any good tutorials on > how > > to do something like this. > > > > To be more exact in what I am trying to do, imagine it is an expense > report > > application in which a user has to enter the expense amount, a > description, > > and select the category under which the expense belongs. The form > consists > > of 5 rows, each row consisting of a field to enter each piece of > information > > for a single expense. The form would also offer the user the chance to > add > > or subject rows. > > > > I am looking for a tutorial that covers both the view and controller > side of > > doing this as I am fairly new to Rails. > > > > Thank you for you help with this. > > > > Chris Johnston > > > > --www.fuzzylizard.com > > > > You know you''ve achieved perfection in design, Not when you have nothing > > more to add, But when you have nothing more to take away. > > - Antoine de Saint-Exupery > > > > >-- www.fuzzylizard.com You know you''ve achieved perfection in design, Not when you have nothing more to add, But when you have nothing more to take away. -- Antoine de Saint-Exupery --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chris Johnston
2007-Jun-09 03:06 UTC
Re: Any tutorials on how to do multiple row (data grid like) form?
Hi,
It isn''t working for me. Are there any good tutorials on putting
together
complex forms?
What I have is this:
Object A, in my example it is ExpenseReport. ExpenseReport contains several
fields of its own like submitted_date, current_project, comments.
It also has a collection of LineItems which contains the amount,
establishment, comments.
A LineItem contains an ExpenseType which is another model object. In the
form, this would be represented by a drop down box. So the whole form looks
something like this:
<% form_for :report, :url => { :action => ''create''}
do |form| %>
<label for="report_project">Name</label>
<%= text_field ''report'', :project, :size => 40
%>
<label for="report_submit_date">Report Submitted
on</label>
<%= datetime_select ''report'',
''submit_date'' %>
Report Line Item</legend>
<% fields_for :line_items do |line_item_form| %>
<% @line_items.each_with_index do |line_item, index| %>
<% fields_for :expense_categories do |expense_category| %>
<%= expense_category.collection_select(:id,
@expense_category, :id, :name) %>
<% end %>
<%= text_field :line_item_form, :amount, :index => index
%>
<% end %>
<% end %>
<label for="report_comments">Comments</label>
<%= text_area ''report'', ''comments'',
:rows => 5, :cols => 60 %>
<%= submit_tag "Create" %>
<% end %>
The problem that I am having right now is twofold; first, when I use the
code listed below to extract the line_items and create those objects I am
getting a ''nil object'' error and second, in the params, there
is only one
listing for the expense_category instead of 5.
Anyone have ideas or tutorials they can point me to for this kind of thing?
Thanks,
Chris
On 6/6/07, tmac <mcintyre.tim-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
>
> I think you may be looking for something like this:
>
> <% form_for :expenses do |form| %>
> <% @expenses.each_with_index do |expense, index| %>
> <%= form.text_field(:amount, :index => index) %>
> <%= form.text_field(:description, :index => index) %>
> <% end %>
> <% submit_tag %>
> <% end %>
>
> then in the controller you should be able to access the data as a hash
> of hashes:
>
> params[:expenses].keys.each do |index|
> Expense.create(params[:expenses][index])
> end
>
> or however you want to handle that.
>
> None of that is tested but I >think< that is the general idea.
>
> Hope that helps!
> Tim
>
> On Jun 6, 7:06 pm, "Chris Johnston"
<fuzzyliz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > Hello,
> >
> > I am trying to create a multiple row / data grid like input form and
am
> not
> > sure how to proceed. I am wondering if there are any good tutorials on
> how
> > to do something like this.
> >
> > To be more exact in what I am trying to do, imagine it is an expense
> report
> > application in which a user has to enter the expense amount, a
> description,
> > and select the category under which the expense belongs. The form
> consists
> > of 5 rows, each row consisting of a field to enter each piece of
> information
> > for a single expense. The form would also offer the user the chance to
> add
> > or subject rows.
> >
> > I am looking for a tutorial that covers both the view and controller
> side of
> > doing this as I am fairly new to Rails.
> >
> > Thank you for you help with this.
> >
> > Chris Johnston
> >
> > --www.fuzzylizard.com
> >
> > You know you''ve achieved perfection in design, Not when you
have nothing
> > more to add, But when you have nothing more to take away.
> > - Antoine de Saint-Exupery
>
>
> >
>
--
www.fuzzylizard.com
You know you''ve achieved perfection in design, Not when you have
nothing
more to add, But when you have nothing more to take away.
-- Antoine de Saint-Exupery
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---