|
Hi,
also der Controller dazu sieht folgendermaßen aus:
def new @user = User.new @user.build_address end def create @user = User.new(params[:user]) respond_to do |format| if @user.save format.html { redirect_to(users_path, :notice => "User successfully created.") } else format.html { flash[:error] = "Fehler!" render "new" } end end end
def edit @user = User.find(params[:id]) end def update @user = User.find(params[:id]) respond_to do |format| if @user.update_attributes(params[:user]) format.html { redirect_to(users_path, :notice => "User successfully changed.") } else format.html { redirect_to(edit_user_path(@user), :error => "Could not update user!") } end end end
und die Views (new.html.haml):
.row .span9 #content %h1 Neuer Benutzer = render :partial => "shared/messages" %ul.errors - @user.errors.each do |error| %li= error - form_for @user, :html => { :class => "form-horizontal" } do |f| .control-group %label{:for => "email", :class => "control-label"} E-Mail .controls = f.text_field :email, :class => "ui-textfield" .control-group %label{:for => "first_name", :class => "control-label"} Vorname .controls = f.text_field :first_name, :class => "ui-textfield" .control-group %label{:for => "last_name", :class => "control-label"} Nachname .controls = f.text_field :last_name, :class => "ui-textfield" .control-group %label{:for => "acronym", :class => "control-label"} Akronym .controls = f.text_field :acronym, :class => "ui-textfield" .control-group %label{:for => "password", :class => "control-label"} Passwort .controls = f.password_field :password, :class => "ui-passwordfield" .control-group = f.label :password_confirmation, 'Passwortbestätigung', :class => 'ui-passwordfield' .controls = f.password_field :password_confirmation, :class => "ui-passwordfield" .control-group = f.label :role, "Rolle", :class => "control-label" .controls = f.select("role", User::ROLES, {:include_blank => 'Bitte wählen'}) %h3 Adressdaten = fields_for :address do |af| = af.text_field :street = af.text_field :street_addon = af.text_field :zip = af.text_field :country .control-group .controls = f.submit "Benutzer anlegen", :class => "btn btn-success" .span3 #left = link_to 'Zurück zur Benutzerliste', users_path
edit.html.haml:
%h1= "Benutzer #{@user.email} ändern"
- form_for @user, :html => {:class => 'form-horizontal'} do |f| .control-group = f.label :email, :class => 'control-label' = f.text_field :email, {:disabled => true} .control-group = f.label :first_name, :class => 'control-label' = f.text_field :first_name .control-group = f.label :last_name, :class => 'control-label' = f.text_field :last_name .control-group = f.label :acronym, :class => 'control-label' = f.text_field :acronym .control-group = f.label :password, :class => 'control-label' = f.password_field :password = f.password_field :password_confirmation .control-group = f.label :role, :class => 'control-label' = f.select("role", User::ROLES) %h3 Adressdaten = fields_for :address do |af| = af.text_field :street = af.text_field :street_addon = af.text_field :zip = af.text_field :country %p= f.submit 'speichern', :class => 'btn btn-success' .right %p= link_to "Zurück zur Benutzerliste", users_path
Viele Grüße Martin
|