Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running list of errors encountered & their fixes #32

Open
jendiamond opened this issue Aug 1, 2016 · 4 comments
Open

Running list of errors encountered & their fixes #32

jendiamond opened this issue Aug 1, 2016 · 4 comments

Comments

@jendiamond
Copy link
Owner

jendiamond commented Aug 1, 2016

While installing simple form.

Error

$ rails generate simple_form:install --bootstrap
/home/vagrant/.rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/configuration.rb:37:inpwd': No such file or directory - getcwd (Errno::ENOENT)`

Fix

http://stackoverflow.com/questions/28390149/rails-generate-error-no-such-file-or-directory-getcwd
$ ps ax | grep spring

 9631 pts/1    Sl     0:00 spring server | railsgirls-signup | started 42 hours ago                                
22872 ?        Ssl    0:00 ruby -I /home/vagrant/.rvm/gems/ruby-2.3.0/gems/bundler-1.11.2/lib -I /home/vagrant/.rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib -e require 'spring/application/boot'
22897 pts/0    S+     0:00 grep --color=auto spring

I ran $ spring stop

Then it was fixed


@jendiamond
Copy link
Owner Author

jendiamond commented Aug 16, 2016

While adding the paperclip to the user_tutorial page which uses simple form.

NoMethodError in Tutorials#user_tutorials

Showing /vagrant/railsgirls-signup/app/views/tutorials/_form.html.erb where line #2 raised:

undefined method `model_name' for nil:NilClass
Extracted source (around line #2):

<div style="background-color:#ccc09e; padding:10px">
  <%= simple_form_for @tutorials, html: {multipart: true} do |f| %>
    <%= f.error_notification %>

    <div class="form-inputs">
      <%= f.file_field :tryruby_image, label: "Try Ruby" %>

http://stackoverflow.com/questions/11093848/rails-undefined-method-model-name-for-nilclassclass

@jendiamond
Copy link
Owner Author

jendiamond commented Aug 17, 2016

Paperclip gem

If you click the upload button without adding a photo you receive this error

ActionController::ParameterMissing in TutorialsController#update
param is missing or the value is empty: tutorial

Extracted source (around line #65):

    def tutorial_params
      params.require(:tutorial).permit(:tryruby_image, :trygit_image,
        :terminal_image, :htmlcss_image, :image, :user_id)
    end
end

This is the tutorial object that is missing:

"tutorial"=>{"trygit_image"=>#<ActionDispatch::Http::UploadedFile:0x007fdb44656f40 @tempfile=#Tempfile:/tmp/RackMultipart20160817-15847-1bkl554.png, @original_filename="trygit.png", @content_type="image/png", @headers="Content-Disposition: form-data; name="tutorial[trygit_image]"; filename="trygit.png"\r\nContent-Type: image/png\r\n">}


Solution:

The if params[:tutorial] cjecks whether or not a photo is being uploaded if it is not then nothing will be created.

 def update
    if params[:tutorial]
      if @tutorial.update(tutorial_params)
        redirect_to user_tutorial_path(@user, @tutorial), notice: 'Tutorial was successfully updated.'
      else
        render :edit
      end
    end
    redirect_to :back
  end

@jendiamond
Copy link
Owner Author

jendiamond commented Aug 17, 2016

AbstractController::DoubleRenderError in TutorialsController#update
Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".

 # PATCH/PUT /tutorials/1
  def update
    if params[:tutorial]
      if @tutorial.update(tutorial_params)
        redirect_to user_tutorial_path(@user, @tutorial), notice: 'Tutorial was successfully updated.' and return
      else
        render :edit
      end
    end
    render :edit
  end

http://blog.arkency.com/2014/07/4-ways-to-early-return-from-a-rails-controller/

@jendiamond
Copy link
Owner Author

jendiamond commented Aug 17, 2016

Missing Image


Solution:

<% if @tutorial.missing_image?(@tutorial.trygit_image).nil? %>
  <%= image_tag @tutorial.trygit_image.url(:medium,) %>
<% end %>

tutorial.rb

def missing_image?(image)
  image.url.match(/missing.png/)
end

trygit_imag is the image object created by imagemagic

image.url is the missing png string


pry(#<Tutorial>)> url
=> #<Paperclip::Attachment:0x007ff59c328748
 @dirty=false,
 @errors={},
 @instance=
  #<Tutorial:0x000000033a4528
   id: 16,
   try_ruby: nil,
   terminal: nil,
   try_git: nil,
   html_css: nil,
   user_id: 123,
   created_at: Wed, 17 Aug 2016 18:40:47 UTC +00:00,
   updated_at: Wed, 17 Aug 2016 19:11:13 UTC +00:00,
   image_file_name: nil,
   image_content_type: nil,
   image_file_size: nil,
   image_updated_at: nil,
   tryruby_image_file_name: "0c1a99b70bb1c4efa5b2b6f6e846b1407500665b_m.jpg",
   tryruby_image_content_type: "image/jpeg",
   tryruby_image_file_size: 26563,
   tryruby_image_updated_at: Wed, 17 Aug 2016 19:11:12 UTC +00:00,
   terminal_image_file_name: nil,
   terminal_image_content_type: nil,
   terminal_image_file_size: nil,
   terminal_image_updated_at: nil,
   trygit_image_file_name: nil,
   trygit_image_content_type: nil,
   trygit_image_file_size: nil,
   trygit_image_updated_at: nil,
   htmlcss_image_file_name: nil,
   htmlcss_image_content_type: nil,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant