markdown Preparando os控制器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Preparando os控制器相关的知识,希望对你有一定的参考价值。

## Preparando os Controllers ##

### favorites_controller ###

```ruby
class Api::V1::FavoritesController < ApplicationController
  before_action :set_favorite, only: :destroy
  # skip_before_action :verify_authenticity_token

  def index
    @favorites = current_user.favorites.all render json:
    Api::V1::WatchableSerializer.new(@favorites.map(&:favoritable)).seria lized_json
  end

  def create
    @favorite = Favorite.new(favorite_params)
    if @favorite.save
      head :ok
    else
      render json: { errors: @favorite.errors.full_messages }, status: :unprocessable_entity
    end
  end

  def destroy
    @favorite.destroy
    head :ok
  end

  private

    def set_favorite
      @favorite = Favorite.find_by(favoritable_type: params[:type].capitalize!, favoritable_id: params[:id], user: current_user)
    end

    def favorite_params
      params.require(:favorite).permit(:favoritable_type, :favoritable_id).merge(user: current_user)
    end
end

```

以上是关于markdown Preparando os控制器的主要内容,如果未能解决你的问题,请参考以下文章

Sublime Text 3预览Markdown

markdown os库python

markdown OS X热键 - 快捷方式

markdown Chrome OS

markdown 键盘仅OS X.

markdown OS发布