I’m trying to pass some parameters (count) from a form to a model.
The model basically creates a user X times.
In our form, we have this:
= f.text_field :count
And I can see this is submitted properly in the dev. log:
user"=>{"count"=>"2"}
I’ve tried this in my controller:
@user = User.generate(params[:count])
Generate is then supposed to call this in my user model:
def self.generate(count=10)
count.times do
.....
end
I basically need the ’10’ replaced with the count from form.
How can I go about this?
— UPDATE 1 —
I’ve edited as below but get had to change from count to usercount because I think that’s reserved in rails..
I have this in my controller:
@user = User.generate(params[:user][:usercount])
This in my user.rb:
attr_accessor :usercount
def self.generate
usercount.times do
...
end
When I submit, I get this:
ArgumentError (wrong number of arguments (1 for 0)):
app/models/user.rb:22:in `generate'
app/controllers/users_controller.rb:38:in `new_users_create'
Really frustrating…
should work fine.