ruby - How to read checkbox in rails I get to many argument to send emails -
i trying create select list of users on submit form send email. such has welcome these people website. problem can't seem iterate through list of checkbox able send email each single email. here form
<%= form_tag(invites_path) %> <% @contacts.each |c|%> <div> <%= label_tag 'accept', c[:email] %> <%= check_box_tag 'accept[]', c[:email], checked = true %> <% end %> <%= submit_tag "send invitations" %> <% end %>
now invites_path controller is, c[:email] email of each users desired. here controller , having issues.
# if there more 1 checkbox selected if not params[':accept'].nil? params[':accept'].split.each |u| invitesmailer.invite_confirm(current_customer, u).deliver end else # 1 checkbox selected invitesmailer.invite_confirm(current_customer,params[':accept']).deliver end
why can't read it
if select 1 checkbox or multiple following error wrong number of arguments (2 1)
line
invitesmailer.invite_confirm(current_customer,params[':accept']).deliver
the parameters follow
{"utf8"=>"✓", "authenticity_token"=>"dnqpngrosw6bxrwayxjnrc8qoqr+a228ysmtfyucc3y=", "accept"=>["example@gmail.com", "example2@gmail.com"],"commit"=>"send invitations"}
i note try follow tutorial check box send email ruby on rails, bit confused on checkbox
update: mailer controller
def invite_confirm(curuser,usemail) @greeting = "hi" @user = curuser mail to: usemail, subject: "whereyouwhere invitation" end
can read through following , let me know if solves issue.
first name of params
i'm pretty sure there's hackish way param named ':accept'
may valid param name in case, it's not want. change instances of params[':accept']
params[:accept]
or params['accept']
.
second if block
change if
block following code. since params[:accept]
array. don't need call split on , else block not needed.
if params[:accept].present? params[:accept].each |email| invitesmailer.invite_confirm(current_customer, email).deliver end end
Comments
Post a Comment