I had a weird problem. I defined a collection_select in my form, something like this:
<%= f.collection_select :campaign_id, @campaigns, :id, :title %>
When I went to the form, the page loaded, and the select populated correctly. However, when I submitted the form, I would get the “undefined method `map’ for nil:NilClass” error.
By mistake, I realized that the sometimes the form posted and sometimes it didn’t. Then I realized that there were Active Record validation errors with the submitted form, but the page wasn’t showing, so I couldn’t see that these errors occurred (even while looking at the logs).
I had to search how to fix this, and eventually found this Stack Overflow question.
The solution by Wes Foster, worked for me to ensure that the collection was getting determined when the new action was rendered (after the record didn’t create).
class MyController < ApplicationController
before_action :set_select_collections, only: [:edit, :update, :new, :create]
@campaigns = current_user.business.campaigns
Incidentally, if you’re receiving this error and your form isn’t even loading, it probably means that you didn’t define the collection value in your controller (@campaigns in this example).
I had some errors occurring in my controller, but it wasn’t displaying in my views. So I had to figure out how to see what was happening since I didn’t see any messages in the logs that were helpful either.
I found the solution in one of the answers here on Stack Overflow.
By adding this to my controller (it was the creation of a model – @user):
This recorded the error in my logs (one of my model validations needed to be changed).
I was receiving the error “The plain HTTP request was sent to HTTPS port” error”, Nginx error 400. The problem was a an Nginx configuration error. I found the solution in this StackOverflow question. In the config file with your server info (mine was in /etc/nginx/sites-enabled/default):
make these changes:
listen 443 default ssl;
# ssl on - remember to comment this out
In order to create a SSL Certificate, you need to generate a CSR, or Certificate Signing Request. I ran into some issues when generating one from Windows, so I wanted to document the steps that I took.
- went to http://slproweb.com/products/Win32OpenSSL.html to download Win32 OpenSSL v1.0.0k
- installed OpenSSL
- I received an error regarding C++ during the install, so I installed Visual C++ 2008 Redistributables from the same page I downloaded OpenSSL
- Run a command prompt (cmd.exe from the search box in the Windows start menu)
- When I tried to run an OpenSSL command, I received an error that a file could not be found (WARNING: CAN’T OPEN CONFIG FILE: /USR/LOCAL/SSL/OPENSSL.CNF)
- As noted here, you have to set the environmental variable by typing this into the cmd: set OPENSSL_CONF=c:\[PATH TO YOUR OPENSSL DIRECTORY]\bin\openssl.cfg
- navigate to the bin directory
- enter your openssl command to generate your csr. For me, it was:
openssl req -nodes -newkey rsa:2048 -keyout myserver.key -out myserver.csr
- this created key and csr files I could use for creating my SSL certificate
When I had to set up a new Windows PC with Rails, I ran in to a mysterious error where I couldn’t view my app because of purported problems with my .coffee.js files. However, I knew there was no issue with the files since they were created during scaffolding and had only comments in them. Furthermore, I was able to run the same code on my other PC fine, as is.
When I viewed the –trace there was nothing of note (except listing that the coffee files had issues with them). When I tried to load the view, I did see this though “ExecJS::RuntimeError in Home#index”
Fortunately, I found the solution in this thread which explains that this is the result of Node.js not on a PC, or the path not set correctly in Windows environment variables. I downloaded the Windows installer (.msi) file and installed Node.js and added the path to the PATH environment variable. After I restarted my Rails server, the error went away.
I ran into an issue with my manifest.json file when trying to submit my app to the Google Chrome Store. I followed the directions, but apparently there was a detail that was so simple, it wasn’t documented. The documentation says to create a text file to put the manifest code, and then to save it as manifest.json. However, when I loaded my zip file, I kept receiving error messages saying that the manifest.json was not at the root level and couldn’t be found. The only thing was the file was of course there, and there were no subdirectories in my zip file.
It turned out to be a stupid, basic mistake.
When I looked at the properties of the file, the file was a .txt file, and the full name was actually manifest.json.text even though I couldn’t see the .txt part in Windows Explorer. I found the solution was that when the file was created, I should have named it manifest.json, but also when I saved it in Notepad, I should have selected “Save as type” as “All Files”. When you look at the properties, the file type will now be “json” instead of “txt”.
I was receiving a translation missing message that was showing up on my page views for my ActiveAdmin page. To correct this, I found the solution on Stack Overflow which said that these translations were just missing from my en.yml file in locales, and to replace my existing one with the one here (that ActiveAdmin uses):
I was receiving the “identify ‘-format’ ‘%wx%h’ ” error with Paperclip. The reason is because Paperclip requires ImageMagick if images are manipulated, and the path must be specified for this to happen. In order to find the path in Windows, what I did was:
- open a command prompt (CMD from the start menu)
- navigate to c://
- type “PATH”
- it should show the path(s) that can be used for ImageMagick
- I added this line to development.rb
Paperclip.options[:command_path] = “/bin” #(in place of “/bin” put your path)
Restart your server.
Devise’s Sign Out wasn’t working for me. I’ve seen other solutions, but they didn’t worked for me. However, I found an answer that worked for me on Devise’s wiki.
Previously, I used this link:
<%= link_to "Logout", destroy_user_session_path, method: :delete %>
However, that wasn’t working, so I changed (in config/initializers/devise.rb in ):
config.sign_out_via = :delete
config.sign_out_via = :get
and revised the link to (removed “method: :delete”):
<%= link_to "Logout", destroy_user_session_path %>
I was receiving this error after switching to the MySQL2. It turns out the reason is because I needed to update my MySQL connector.
To do that I
(1) went to: http://www.mysql.com/downloads/connector/
(2) I selected Connector/C (libmysql)
(3) I downloaded the Windows (x86, 32-bit), ZIP Archive no-install
(4) I placed it in my ruby/bin directory, which for me was in: C:\RailsInstaller\Ruby1.9.3\bin