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
User.create! | |
# -> #<User id: 2, can_do_dangerous_things: false, ...> | |
User.create!(:can_do_dangerous_things => true) | |
# -> ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: can_do_dangerous_things | |
User.create!(:permissions => {:can_do_dangerous_things => true}) | |
# -> #<User id: 2, can_do_dangerous_things: true, ...> |
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
config.active_record.whitelist_attributes = true |
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 | |
# Has attributes: [:username, :hashed_password, :is_admin] | |
attr_accessible :username | |
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 | |
# Has attributes: [:username, :hashed_password, :is_admin] | |
attr_accessible :username | |
attr_accessible :username, :is_admin, :as => :internal | |
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
User.update_attributes(:username => "iHiD") | |
User.update_attributes({:username => "iHiD", :is_admin => true}, :as => :internal) |
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 ProjectsController < ApplicationController | |
def index | |
@projects = Project.where( | |
"user_id = #{current_user.id} AND name LIKE '#{params[:name]}%'" | |
) | |
#... | |
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
SELECT * FROM "projects" | |
WHERE user_id = 1 | |
AND name LIKE '' OR created_at LIKE '%' |
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
@projects = Project.where(:user_id => current_user.id). | |
where('name LIKE ?', "#{params[:name]}%") |
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
# Use a hash | |
Project.where(:user_id => current_user.id) | |
# Use placeholders | |
Project.where("user_id = ?", current_user.id) | |
# Use bind variables | |
Project.where("user_id = :user_id", {:user_id => current_user.id}) |
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 ProjectsController < ApplicationController | |
def index | |
@project = current_user.projects.where('name LIKE ?', "#{params[:name]}%") | |
#... | |
end | |
end |