class CinnostiFirmiesController < ApplicationController
  # GET /cinnosti_firmies
  # GET /cinnosti_firmies.json
  def index
    @firmy = Firmy.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @cinnosti_firmies }
    end
  end

  # GET /cinnosti_firmies/1
  # GET /cinnosti_firmies/1.json
  def show
    @cinnosti_firmy = CinnostiFirmy.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @cinnosti_firmy }
    end
  end

  # GET /cinnosti_firmies/new
  # GET /cinnosti_firmies/new.json
  def new
    @firmy = Firmy.find(params[:id])

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @cinnosti_firmy }
    end
  end

  # GET /cinnosti_firmies/1/edit
  def edit
    @cinnosti_firmy = CinnostiFirmy.find(params[:id])
  end

  # POST /cinnosti_firmies
  # POST /cinnosti_firmies.json
  def create
    @firmy = Firmy.find(params[:id])
    @cinnosti = Cinnosti.find(params[:firma][:cinnosti])
    
    @firmy.cinnosti << @cinnosti
    
    redirect_to  cinnosti_firmies_path
  end

  # PUT /cinnosti_firmies/1
  # PUT /cinnosti_firmies/1.json
  def update
    @cinnosti_firmy = CinnostiFirmy.find(params[:id])

    respond_to do |format|
      if @cinnosti_firmy.update_attributes(params[:cinnosti_firmy])
        format.html { redirect_to @cinnosti_firmy, notice: 'Cinnosti firmy was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @cinnosti_firmy.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /cinnosti_firmies/1
  # DELETE /cinnosti_firmies/1.json
  def destroy
    @cinnosti_firmy = CinnostiFirmy.find(params[:id])
    @cinnosti_firmy.destroy

    respond_to do |format|
      format.html { redirect_to cinnosti_firmies_url }
      format.json { head :no_content }
    end
  end
end
