Class: ContentsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/contents_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/contents_controller.rb', line 80

def autocomplete
  @contents = Content.find_for_autocomplete(params.merge(project_id: sessions_current_project_id))
  data = @contents.collect do |t|
    {id: t.id,
     label: ApplicationController.helpers.(t),
     response_values: {
         params[:method] => t.id
     },
     label_html: ApplicationController.helpers.(t)
    }
  end

  render :json => data
end

- (Object) content_params (private)

Never trust parameters from the scary internet, only allow the white list through.



109
110
111
# File 'app/controllers/contents_controller.rb', line 109

def content_params
  params.require(:content).permit(:text, :otu_id, :topic_id, :type)
end

- (Object) create

POST /contents POST /contents.json



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/contents_controller.rb', line 30

def create
  @content = Content.new(content_params)

  respond_to do |format|
    if @content.save
      format.html { redirect_to @content.metamorphosize, notice: 'Content was successfully created.' }
      format.json { render :show, status: :created, location: @content.metamorphosize }
    else
      format.html { render :new }
      format.json { render json: @content.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

DELETE /contents/1 DELETE /contents/1.json



60
61
62
63
64
65
66
# File 'app/controllers/contents_controller.rb', line 60

def destroy
  @content.destroy
  respond_to do |format|
    format.html { redirect_to contents_url }
    format.json { head :no_content }
  end
end

- (Object) download

GET /contents/download



96
97
98
# File 'app/controllers/contents_controller.rb', line 96

def download
  send_data Content.generate_download( Content.where(project_id: sessions_current_project_id) ), type: 'text', filename: "contents_#{DateTime.now.to_s}.csv"
end

- (Object) edit

GET /contents/1/edit



25
26
# File 'app/controllers/contents_controller.rb', line 25

def edit
end

- (Object) index

GET /contents GET /contents.json



9
10
11
12
# File 'app/controllers/contents_controller.rb', line 9

def index
  @recent_objects = Content.recent_from_project_id($project_id).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



68
69
70
# File 'app/controllers/contents_controller.rb', line 68

def list
  @contents = Content.with_project_id($project_id).order(:id).page(params[:page]) #.per(10) #.per(3)
end

- (Object) new

GET /contents/new



20
21
22
# File 'app/controllers/contents_controller.rb', line 20

def new
  @content = Content.new
end

- (Object) search



72
73
74
75
76
77
78
# File 'app/controllers/contents_controller.rb', line 72

def search
  if params[:id].blank?
    redirect_to content_path, notice: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to content_path(params[:id])
  end
end

- (Object) set_content (private)

Use callbacks to share common setup or constraints between actions.



103
104
105
106
# File 'app/controllers/contents_controller.rb', line 103

def set_content
  @content = Content.with_project_id($project_id).find(params[:id])
  @recent_object = @content
end

- (Object) show

GET /contents/1 GET /contents/1.json



16
17
# File 'app/controllers/contents_controller.rb', line 16

def show
end

- (Object) update

PATCH/PUT /contents/1 PATCH/PUT /contents/1.json



46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/contents_controller.rb', line 46

def update
  respond_to do |format|
    if @content.update(content_params)
      format.html { redirect_to @content.metamorphosize, notice: 'Content was successfully updated.' }
      format.json { render :show, status: :ok, location: @content.metamorphosize }
    else
      format.html { render :edit }
      format.json { render json: @content.errors, status: :unprocessable_entity }
    end
  end
end