Skip to content

Instantly share code, notes, and snippets.

@universal
Last active July 27, 2016 13:30
Show Gist options
  • Save universal/22d19c0f3f67453fe893fa1007ac9048 to your computer and use it in GitHub Desktop.
Save universal/22d19c0f3f67453fe893fa1007ac9048 to your computer and use it in GitHub Desktop.
## ERROR
Showing c:/Sites/postgreSQL_test/app/views/welcome/index.html.erb where line #9 raised:
undefined method `each' for nil:NilClass
Marked: <% @result.each do |element| %>
<Table>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
<% @result.each do |element| %>
<% element.each do |key, value| %>
<tr>
<td>
<%= key %>
</td>
<td>
<%= value %>
</td>
</tr>
<% end %>
<% end %>
<Table>
class Project < ApplicationRecord
end
class WelcomeController < ApplicationController
def index
# @connection = ActiveRecord::Base.establish_connection(
# :adapter => "postgresql",
# :host => "****",
# :database => "*****",
# :username => "****",
# :password => "*****"
# )
#
# sql = "SELECT project_name FROM project"
# @result = @connection.connection.execute(sql);
project = Project.all
@result = project
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment