Ruby/RAILS

Ruby code posted by Mat
created at 03 Jun 14:43

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  def create
    @presentation = Presentation.new(params[:presentation])
    begin
      @chapters = Converter::presentation(@presentation.youbbcode)
    rescue Converter::ConversionException => e
      flash[:alert] = "Error during convertion : #{e.message}"
      return redirect_to presentations_path
    end
    @chapters.each_with_index do |c,i|
      page = Ppage.new
      page.title = c[:title]
      page.summary = c[:summary]
      page.number = i+1 #Start at 1
      page.html = c[:content]
      page.presentation = @presentation
      
      if PIC_REHOST
        #CarrierWave Hack

      end
      
      unless page.save
        flash[:alert] = "Error during page n°#{i+1}"
        return redirect_to presentations_path
      end
    end
    @presentation.is_online = true
    @presentation.user = current_user if user_signed_in?
    if @presentation.save
      flash[:notice] = "Presentation sucessfully uploaded and converted"
      redirect_to presentation_path(@presentation)
    else
      flash[:alert] = "Error during presentation validation"
      redirect_to presentations_path
    end
  end
1.12 KB in 3 ms with coderay