Loganathan Sellapa
2012-Jan-26 19:00 UTC
How to add multiple user create on single form using ActiveAdmin
HI All, I am currently creating an Admin utility for courier management service, where I need to include a form to *submit two users(same model) on same form *, I don''t know to implement exactly but duplicated the user form twice which is displaying the form twice on the browser but unable to save the both the users, listed below my Admin customer register file and attached the screen shot for your reference . Also want to know, how to add *additional business logics to admin*, for example adding print functionality for the single user on ''view'' page. ActiveAdmin.register Customer do form do |f| #User one f.inputs "Sender Details" do f.input :name f.input :email f.input :street f.input :city f.input :state f.input :pin f.input :customer_type,:as => :select, :collection => [["Package Sender", "Package Sender"], ["Package Receiver","Package Receiver"]] end #User two f.inputs "Receiver Details" do f.input :name f.input :email f.input :street f.input :city f.input :state f.input :pin f.input :customer_type,:as => :select, :collection => [["Package Sender", "Package Sender"], ["Package Receiver","Package Receiver"]] end f.inputs do f.has_many :packages do |p| p.input :weight p.input :amount p.input :received_date p.input :amount end end f.buttons end end regards, Loganathan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bala TS
2012-Jan-27 04:49 UTC
Re: How to add multiple user create on single form using ActiveAdmin
controller ---------- your erb like this way: ---------------------------------------------------------------------- user_name | email | street | city | state | ---------------------------------------------------------------------- user1 | abc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org | x | xx | TN | ---------------------------------------------------------------------- user2 | cde-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org | y | yy | KL | ---------------------------------------------------------------------- use table structure: the first row is header: the second row is td form like this way <table> <tr> <td>user_name</td> <td>email</td> <td>street</td> <td>city</td> <td>state</td> </tr> <%= form_tag "action" ,:mode=>"update",:multipart => true do %> <% for i in 0..1%> <%= text_field_tag :"user_name_#{i}",""%> <%= text_field_tag :"email_#{i}",""%> <%= text_field_tag :"street_#{i}",""%> <%= text_field_tag :"city_#{i}",""%> <%= text_field_tag :"state_#{i}",""%> <% end%> <%= submit_tag "update" %> <%end%> </table> controller file: if params[:mode]=="update" count = 0 loop{ user_name = "user_name_"+count.to_s email = "email_"+count.to_s street = "street_"+count.to_s city = "city_"+count.to_s state = "state_"+count.to_s if !params[user_name].blank? User.create( :user_name => params[user_name], :email => params[user_name], :street => params[user_name], :city => params[user_name], :state => params[user_name] ) end count = count + 1 user_name = "user_name_"+count.to_s break if params[user_name].blank? } end bye:) bdeveloper01 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Dave Aronson
2012-Jan-27 13:50 UTC
Re: How to add multiple user create on single form using ActiveAdmin
On Thu, Jan 26, 2012 at 14:00, Loganathan Sellapa <loganathan.ms-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I need to include a form to submit two users(same model) on same form,Disclaimer: I haven''t tried ActiveAdmin, so this is just about Rails in general. I did something sorta like this in The Decider. The Edit Decision view includes editable display of each Decision''s Factors, Alternatives, and Rankings. (Which should have been called Ratings but that''s another story.) These are each separate models. You can use the app yourself at http://thedecider.herokuapp.com and see the code at https://github.com/davearonson/thedecider/. To do like I did, just have your Customer model say it accepts nested attributes for users, and in your order view, use fields_for when displaying the Users. IIRC, that was all I had to do! (Nitpick: I don''t understand why a Customer would be/have two Users. Are you sure your model shouldn''t be Shipment or Order or ServiceCall or something like that?) I couldn''t find any good clear online documentation of how this works and what you need to do. By experimenting, I found that Rails will take care of the rest with its wonderful behind-the-scenes magic of tagging things with appropriate name and id attributes in the HTML, and interpreting those when returned, so you pretty much don''t need to do *anything*! You *can* define an attributes= method if you want, but chances are very good that what Rails will do by default is exactly what you want, and any attempt to provide that yourself will just mean having write a lot of tedious code. -Dave -- Dave Aronson: Available Cleared Ruby on Rails Freelancer (NoVa/DC/Remote) -- see www.DaveAronson.com, and blogs at www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.