Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

How to handle permission in rails

class Post
  has_many :post_users
  has_many :users, through: :post_users
end

class PostUser
  belongs_to :post
  belongs_to :user
end

class User
  has_many :post_users
  has_many :posts, through: :post_users
end
Comment

How to handle permission in rails

class Ability
  include CanCan::Ability

  def initialize(user)
    if user.present?  # additional permissions for logged in users (they can read their own posts)
      can :read, Post, users: { id: user.id }
    end
  end
end
Comment

PREVIOUS NEXT
Code Example
Ruby :: ruby block_given? method 
Ruby :: find_by column name rails route 
Ruby :: next if ruby 
Ruby :: devise valid password 
Ruby :: rails deliver_later with delay 
Ruby :: my rails server exits automatically 
Ruby :: common functions in rails 
Ruby :: last select in rails 
Ruby :: Or even multiple scope parameters. For example, making sure that a teacher can only be on the schedule once per semester for a particular class. 
Ruby :: og meta tags not working rails 
Ruby :: sequel not ruby 
Ruby :: ruby hash from array 
Ruby :: logback grails log in different files 
Ruby :: write heroku logs 
R :: r delete all variables 
R :: r remove leading and trailing whitespace 
R :: suppress error r 
R :: why is correlation na in r 
R :: how to get the mode in r 
R :: expression in r 
R :: r merge by two columns 
R :: r replace na with 0 
R :: r find nas in dataframe 
R :: for R 
R :: replace character with na r 
R :: select R 
R :: convert country code to country name in r 
R :: Add tab in string r 
R :: L in r 
R :: ways to examine model in r 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =