Sha256: b8133a12ea0dff53b1df53c9a37097464406b4d56ccb02078ffc560c7c3028ee

Contents?: true

Size: 1.66 KB

Versions: 6

Compression:

Stored size: 1.66 KB

Contents

class TranscriptionsController < ActionController::Base
  layout "simple_frame"

  def new
    @<%= @table.singularize %> = <%= @table.classify %>.assign!(current_user)
    # if we're able to assign a filing
    # that the user hasn't done and hasn't been verified
    if @<%= @table.singularize %>.nil?
      redirect_to(root_path, :alert => "You've transcribed all of the filings. Thank you.")
      return
    end
    @transcription = Transcription.new
    @transcription.<%= @table.singularize %> = @<%= @table.singularize %>
  end

  def create
    @<%= @table.singularize %> = <%= @table.classify %>.find(params[:<%= @table.singularize %>_id])
    @transcription = Transcription.new(transcription_params)
    @transcription.<%= @table.singularize %> = @<%= @table.singularize %>
    @transcription.user_id = current_user

    if @transcription.save
      @<%= @table.singularize %>.verify!
      redirect_to(new_transcription_path, :notice => "Thank you for transcribing. Here's another filing.")
    else
      render :action => "new", :alert => "Something went wrong. Please try again."
    end
  end

  private

  # By default, the current user is stored in a cookie.
  # For rigorous purposes, please consider implementing a
  # real login system.
  def current_user
    cookie_name = "#{Rails.application.engine_name}_transcriable_user_id".to_sym
    return cookies[cookie_name] if cookies[cookie_name]
    cookies[cookie_name] = {
      :value   => UUID.new.generate(:compact),
      :expires => 5.years.from_now
    }
    cookies[cookie_name]
  end

  def transcription_params
    params.require(:transcription).permit(<%= transcribable_attrs.keys.map{|q| ":#{q}" }.join(",") %>)
  end  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
transcribable-0.0.6 lib/generators/templates/controller.rb
transcribable-0.0.5 lib/generators/templates/controller.rb
transcribable-0.0.4 lib/generators/templates/controller.rb
transcribable-0.0.3 lib/generators/templates/controller.rb
transcribable-0.0.2 lib/generators/templates/controller.rb
transcribable-0.0.1 lib/generators/templates/controller.rb