mercredi 19 août 2015

Flash Message in a Controller file if loop

The below is my code i want a flash a message stating that room already booked.. for that inside the below link i need to write the flash code

def create
     @room = Room.new(room_params)
     from = @room.fromtime
     to = @room.totime

  c=Room.where("fromtime <= ? AND totime >= ?", from, to)
  if c.exists?(:roomname => @room.roomname) 

      flash[:notice] = ‘Sorry room already booked.’

  else
    binding.pry
      respond_to do |format|
      if @room.save
        #flash.now[:alert] = 'Room booked successfully!'
        Notifier.room_booked(@room).deliver
        format.html { redirect_to @room, notice: 'Room was successfully booked and a notification mail has sent to the admin.' }
        format.json { render :show, status: :created, location: @room }        
      else
        format.html { render :new }
        format.json { render json: @room.errors, status: :unprocessable_entity }
      end
  end

    end
  end

Can anyone please help?

Aucun commentaire:

Enregistrer un commentaire