Tuesday 15 June 2010

ruby on rails - Changing the ActiveModel submitted by a form_for -


I have a form that allows my administrator to create a user I am using STI, A type of admin can specify or user . If I deposit the form with invalid information and the save fails, then my controller resizes the form using the @User model, such as:

  def create user = User.new (user_params) if @ user.save redirect_to admin_users_path, notice: "#{@user.first_name} #{@user.last_name}" user and render: new ending  

I'm running into the problem that the submit button now hash hash with information for admin instead of admin Submits, which means that my method does not work for consulting in the white list:

  def user_params params.require (: user) .permit (: email, first_name, last_name ,: Password: password_confirmation, type ,: role_id) end  

Is there any way that I can modify the submit button so that it is the form of the user Submit in the form of a admin and

and with the button view:

  .col-md-6.col -md-offset-3 = form_for [: admin, @ user], html: {role :: form}, url: admin_users_path do | F | - If @ user.errors.any? % H2 = "# {pluralize (user.errors.count," error ")} This user is restricted from saving:"% ul - @ user.errors.full_messages.each do | Msg | % Li = msg.row # first_name.form-group = f.label: first_name = f.text_field: first_name, autofocus: true, category: 'form-control' .o # # last_name.form-group = f.label: Last_name = F.text_field: last_name, class: 'form-control' .o # email.form-group = f.label: email = f.email_field: email, category: 'form-control' .row .col-md- 6 # User_type.form_group = f.label: type = f.select: type, options_for_select (% w {customer administrator}, selected: @ user.type), category: 'form-control' .col-md-6 # Admin_role Form-group = f.label: role = f.collection_select: role_id, Role.all ,: id ,: name .row # password.form-group = f.label: password = f.password_field: password, category: ' Form -control '.o # password_confirmation.form-group = f.label: password_conf Irmation = f.password_field: password_confirmation, category: 'form-custom' # submit.actions.text-centre = f.submit  

You can add more: as: user: option to form_for Rail.


No comments:

Post a Comment