This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Remove attr_accessible, update README

  • Loading branch information...
Gabe Berke-Williams
Gabe Berke-Williams committed Nov 18, 2013
1 parent b76a14f commit 69a20d90ef2d8f5bdc1f36cb3b8fc69d00fe8dbe
Showing with 15 additions and 6 deletions.
  1. +15 −5 README.md
  2. +0 −1 spec/dummy/app/models/asset.rb
View
@@ -23,7 +23,7 @@ Modify your `application.js` manifest:
### Requirements
-Rails 3.1 (for the asset pipeline), CoffeeScript, and both jQuery and
+Rails 4.0+, CoffeeScript, and both jQuery and
Underscore.js included in your `application.js` manifest.
### Usage
@@ -99,20 +99,25 @@ uploads.
# app/models/asset.rb
class Asset < ActiveRecord::Base
has_attached_file :photo
- attr_accessible :photo
end
# app/controllers/assets_controller.rb
class AssetsController < ApplicationController
def create
- @asset = Asset.new(photo: params[:file])
+ @asset = Asset.new(photo: asset_params[:file])
if @asset.save
render json: @asset
else
head :bad_request
end
end
+
+ private
+
+ def asset_params
+ params.permit(:file)
+ end
end
```
@@ -134,7 +139,6 @@ If attaching assets to a different model, additionally use:
class Post < ActiveRecord::Base
has_many :assets, dependent: :destroy
- attr_accessible :asset_ids, :assets_attributes
accepts_nested_attributes_for :assets
end
@@ -146,10 +150,16 @@ class PostsController < ApplicationController
end
def create
- @post = Post.new(params[:post])
+ @post = Post.new(post_params)
@post.save
respond_with @post
end
+
+ private
+
+ def post_params
+ params.require(:post).permit(:asset_ids, :assets_attributes)
+ end
end
```
@@ -1,4 +1,3 @@
class Asset < ActiveRecord::Base
has_attached_file :file
- attr_accessible :file
end

0 comments on commit 69a20d9

Please sign in to comment.