mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
adding ruby tag to code blocks
This commit is contained in:
parent
558769981e
commit
6a8da1f664
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Let's say you have a basic Post Controller:
|
Let's say you have a basic Post Controller:
|
||||||
|
|
||||||
```
|
```ruby
|
||||||
class PostController < ApplicationController
|
class PostController < ApplicationController
|
||||||
def dashboard
|
def dashboard
|
||||||
render json: @posts
|
render json: @posts
|
||||||
@ -12,7 +12,7 @@ end
|
|||||||
|
|
||||||
Odds are, your serializer will look something like this:
|
Odds are, your serializer will look something like this:
|
||||||
|
|
||||||
```
|
```ruby
|
||||||
class PostSerializer < ActiveModel::Serializer
|
class PostSerializer < ActiveModel::Serializer
|
||||||
attributes :id, :title, :body
|
attributes :id, :title, :body
|
||||||
end
|
end
|
||||||
@ -23,7 +23,7 @@ into the serializer. Here's what you would do:
|
|||||||
|
|
||||||
### posts_controller.rb
|
### posts_controller.rb
|
||||||
|
|
||||||
```
|
```ruby
|
||||||
...
|
...
|
||||||
def dashboard
|
def dashboard
|
||||||
render json: @posts, user_id: 12
|
render json: @posts, user_id: 12
|
||||||
@ -33,7 +33,7 @@ into the serializer. Here's what you would do:
|
|||||||
|
|
||||||
### posts_serializer.rb
|
### posts_serializer.rb
|
||||||
|
|
||||||
```
|
```ruby
|
||||||
...
|
...
|
||||||
def comments_by_me
|
def comments_by_me
|
||||||
Comments.where(user_id: instance_options[:user_id], post_id: object.id)
|
Comments.where(user_id: instance_options[:user_id], post_id: object.id)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user