Last active
January 6, 2016 20:00
-
-
Save andreas-it-dev/f88559899bf2db6f69a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for @analysis, :html => { :multipart => true } do |f| %> | |
<%= render "shared/errors", object: @analysis %> | |
<fieldset> | |
<ol> | |
<li> | |
<%= f.label :title %> | |
<%= f.text_field :title, size: 50, autofocus: true %> | |
</li> | |
<li> | |
<%= f.label :body %> | |
<%= f.text_area :body, rows: 20, cols: 100 %> | |
</li> | |
<li> | |
<%= f.label :trend %> | |
<%= f.check_box :trend %> | |
</li> | |
<li> | |
<%= f.label :images %> | |
<%= f.file_field :images, multiple: true %> | |
<%= f.hidden_field :images_cache, multiple: true %> | |
</li> | |
</ol> | |
<div id="submit"> | |
<% if @analysis.new_record? %> | |
<%= f.submit 'Create Analysis', class: 'button' %> | |
<%= link_to 'Cancel', :back , class: 'button' %> | |
<% else %> | |
<%= f.submit 'Update Analysis', class: 'button' %> | |
<%= link_to 'Cancel', @analysis, class: 'button' %> | |
<% end %> | |
</div> | |
</fieldset> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Analysis < ActiveRecord::Base | |
mount_uploader :images, ImagesUploader | |
validates :title, presence: true | |
validates :body, presence: true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AnalysesController < ApplicationController | |
def index | |
@analyses = Analysis.all | |
end | |
def new | |
@analysis = Analysis.new | |
end | |
def create | |
@analysis = Analysis.new(analysis_params) | |
if @analysis.save | |
flash[:notice] = 'Analysis successfully created.' | |
redirect_to @analysis | |
else | |
render :new | |
end | |
end | |
def edit | |
@analysis = Analysis.find(params[:id]) | |
end | |
def update | |
@analysis = Analysis.find(params[:id]) | |
# fail | |
if @analysis.update(analysis_params) | |
redirect_to @analysis, notice: 'Analysis successfully updated!' | |
else | |
render :edit | |
end | |
end | |
def show | |
@analysis = Analysis.find(params[:id]) | |
end | |
def analysis_params | |
params.require(:analysis).permit(:title, :body, :trend, { images: [] } ) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Processing by AnalysesController#update as HTML | |
Parameters: {"utf8"=>"✓", "authenticity_token"=>"T3GT2UXd7kWkvou5+eVq8UjBepKIqs8wSsQDcOyF5TTf4wyVhR3g7Np3wSTnZv+A4jfy1PDoMnNu32qMvs4UxQ==", "analysis"=>{"title"=>"Analysis Number One", "body"=>"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. \r\n", "trend"=>"1", "images"=>[#<ActionDispatch::Http::UploadedFile:0x007fabb2ba6390 @tempfile=#<Tempfile:/tmp/RackMultipart20160106-17421-wor4pn.png>, @original_filename="2015-07-12_TF.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"analysis[images][]\"; filename=\"2015-07-12_TF.png\"\r\nContent-Type: image/png\r\n">]}, "commit"=>"Update Analysis", "id"=>"1"} | |
Analysis Load (0.1ms) SELECT `analyses`.* FROM `analyses` WHERE `analyses`.`id` = 1 LIMIT 1 | |
(0.1ms) BEGIN | |
(0.2ms) ROLLBACK | |
Completed 500 Internal Server Error in 5ms (ActiveRecord: 0.3ms) | |
TypeError (no implicit conversion of nil into String): | |
app/controllers/analyses_controller.rb:28:in `update' | |
Rendered /home/andreas/.rvm/gems/ruby-2.1.5/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_source.erb (13.1ms) | |
Rendered /home/andreas/.rvm/gems/ruby-2.1.5/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.9ms) | |
Rendered /home/andreas/.rvm/gems/ruby-2.1.5/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.8ms) | |
Rendered /home/andreas/.rvm/gems/ruby-2.1.5/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (24.3ms) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TypeError in AnalysesController#create | |
no implicit conversion of nil into String | |
Extracted source (around line #12): | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
def create | |
@analysis = Analysis.new(analysis_params) | |
if @analysis.save | |
flash[:notice] = 'Analysis successfully created.' | |
redirect_to @analysis | |
Rails.root: /home/andreas/rails/alphatrade | |
Application Trace | Framework Trace | Full Trace | |
app/controllers/analyses_controller.rb:12:in `create' | |
Request | |
Parameters: | |
{"utf8"=>"✓", | |
"authenticity_token"=>"o3RhwSX3A0qT1pOjIVmVxVI2/ZOCNkjjBvUz6YFJjRgz5v6N5TcN4+0f2T4/2gC0+MB11fp0taAi7loV0wJ86Q==", | |
"analysis"=>{"title"=>"Analysis Number One", | |
"body"=>"Lorem ipsum dolor sit amet, | |
consetetur sadipscing elitr, | |
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, | |
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, | |
no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, | |
consetetur sadipscing elitr, | |
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, | |
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, | |
no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, | |
consetetur sadipscing elitr, | |
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, | |
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, | |
no sea takimata sanctus est Lorem ipsum dolor sit amet. \r\n", | |
"trend"=>"1", | |
"images"=>[#<ActionDispatch::Http::UploadedFile:0x007fabb28a8d50 @tempfile=#<Tempfile:/tmp/RackMultipart20160106-17421-1o0zq4a.png>, | |
@original_filename="2015-07-12_ES.png", | |
@content_type="image/png", | |
@headers="Content-Disposition: form-data; name=\"analysis[images][]\"; filename=\"2015-07-12_ES.png\"\r\nContent-Type: image/png\r\n">, | |
#<ActionDispatch::Http::UploadedFile:0x007fabb28a8d28 @tempfile=#<Tempfile:/tmp/RackMultipart20160106-17421-1t97ixv.png>, | |
@original_filename="2015-07-12_NQ.png", | |
@content_type="image/png", | |
@headers="Content-Disposition: form-data; name=\"analysis[images][]\"; filename=\"2015-07-12_NQ.png\"\r\nContent-Type: image/png\r\n">], | |
"images_cache"=>[""]}, | |
"commit"=>"Create Analysis"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImagesUploader < CarrierWave::Uploader::Base | |
include CarrierWave::RMagick | |
storage :file | |
def store_dir | |
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" | |
end | |
version :thumb do | |
process resize_to_fit: [150, 150] | |
end | |
def extension_whitelist | |
%w(jpg jpeg gif png) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddImagesToAnalysis < ActiveRecord::Migration | |
def change | |
add_column :analyses, :images, :text | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment