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

controller

your erb like this way:


user_name | email | street | city | state |

user1 | [email protected] | x | xx | TN |

user2 | [email protected] | y | yy | KL |

use table structure:

the first row is header:
the second row is td

form like this way

<%= 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%>
user_name email street city state

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

On Thu, Jan 26, 2012 at 14:00, Loganathan S.
[email protected] 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 A.: 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs