-
-
Save tubbo/3123884 to your computer and use it in GitHub Desktop.
Mass-assigment attr_accessable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UsersController < ApplicationController | |
| respond_with :html | |
| def create | |
| @user = User.new(params[:user]) | |
| if @user.save | |
| respond_with [:admin, @user], notice: "User succesfully created!" | |
| else | |
| redirect_to 'admin/users/new', alert: "User was not created: #{@user.errors.full_messages.join(',')}" | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User < ActiveRecord::Base | |
| attr_accessible :admin | |
| def admin=(raw_value) | |
| is_admin = (raw_value == "1") | |
| self.write_attribute(:admin, is_admin) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment