Sha256: bc010dd818ad6c0e1393db3022f9b44d34e220e5adb3a304b67f4dfa1ca3a0f1

Contents?: true

Size: 808 Bytes

Versions: 3

Compression:

Stored size: 808 Bytes

Contents

class UsersController < ApplicationController
  before_filter :build_resource, only: [:new, :create]
  before_filter :load_resource, only: [:edit, :update, :edit_without_fields, :events]

  def new
    3.times{ @resource.roles.build }
  end

  def create
    @resource.update_attributes!(resource_params)
    redirect_to edit_user_path(@resource)
  end

  def update
    @resource.update_attributes!(resource_params)
    redirect_to edit_user_path(@resource)
  end

  private

  def scope
    User
  end

  def build_resource
    @resource = scope.new
  end

  def load_resource
    @resource = scope.find(params[:id])
  end

  def resource_params
    DynamicFieldsFor.rails4? ?
      params.fetch(:user, {}).permit(:user_name, roles_attributes: [:id, :role_name, :_destroy]) :
      params[:user]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dynamic-fields-for-1.0.3 spec/rails_app/app/controllers/users_controller.rb
dynamic-fields-for-1.0.2 spec/rails_app/app/controllers/users_controller.rb
dynamic-fields-for-1.0.1 spec/rails_app/app/controllers/users_controller.rb