开发者

Alternative to scoped mass assignment for Rails Stable

开发者 https://www.devze.com 2023-03-07 01:53 出处:网络
I was reading about scoped mass assignment in Rails 3.1 (Edge). I found this feature very helpful. However, I am using Rails stable (specifically 3.0.3).

I was reading about scoped mass assignment in Rails 3.1 (Edge). I found this feature very helpful. However, I am using Rails stable (specifically 3.0.3).

Was wondering, if there was a similar approach for the current stable release 3.0+.

So far, I have come up with this solution. Is there something better?

# CONTROLLER

  def create
    @artist = current_user
    authorize! :manage, @artist # Needed for Cancan to check if user has permission

    re开发者_StackOverflowspond_to do |format|
      if @artist.update_attributes(params[:user])
         @artist.is_artist = true
         @artist.save!
      end
....

# MODEL

class User < ActiveRecord::Base
  attr_accessible :artist_name
...


Check out a railscast on this: http://railscasts.com/episodes/237-dynamic-attr-accessible

0

精彩评论

暂无评论...
验证码 换一张
取 消