Rails - why I'm getting undefined method `name' for nil:NilClass


teabagbrewster
26/4/2016 6:52 am
HOME ยป Web Development

I'm displaying question by categories and each question has its own number. I made it like this(index.html.erb):

<% @categories.each do |category| %>
     <div id=<%= "box#{category.id}" -%>>
        <h1><%= category.name %></h1>
        <% category.questions.each_with_index do |question, i|
%>
            <ul class="question-list" style="display: inline;">
                <li><%= link_to (i + 1), show_path
%></li>
            </ul>
        <% end %>
     </div>
<% end %>

And when I click on question number I would like to show it like this(show.html.erb):

<div class="question-wrapper">
       <h1><%= @category.name %></h1>
       <div class="image left-align">
         <%= question_image_tag(question, :large) %>
       </div>
       <div class="question-text right-align">
        <%= @question.question_name %>
       </div>
       <p><%= @question.answer %></p>
 </div>

This is my controller:

def index
    @categories = Category.all
    @questions = Question.all
end

def show
    @categories = Category.all
    @questions = Question.all
end

Now, I'm getting undefined method `name' for nil:NilClass (also throws error for all methods in show.html.erb) and I can't resolve it.

Question: What should I do to resolve undefined method `name' for nil:NilClass?


Related to : Rails - why I'm getting undefined method `name' for nil:NilClass
weird error with undefined method `gsub' for nil:NilClass and undefined method `strptime' for nil:NilClass RoR 2.3.8
Web Development

Hi I'm trying to read csv file, my code is this:


CSV.foreach(path, {:col_sep => @seperator}) do |row|
#CSV.foreach(File.basename(path), {:col_sep => @seperator}) do |row|
r = Route.new
r.contact_id = contact_id
r.name = row[0]
r.number_range = row[1]
r.rate = row[3].gsub(",", ".").to_f
r.valid_from = DateTime.strptime(row[5], @time_format)
r.currency = @currency
r.save
end

And I'm having a problem in this lines:


r.rate = row[3].gsub(",", ".").to_f
r.valid_
Rails: undefined method `+' for nil:NilClass
Web Development

I have this super simple code in my view:


<% @something.each do |something| %>
<% i = i+1 %>
<div class="row">
<div class="span1"><span class="badge untouched"><%= i %></span></div>
</div>
<% end %>

and get this error


undefined method `+' for nil:NilClass

I have the exact same code in another view and there it works!
However, I'm new to rails and you see what I want to do. Maybe there is a more common way to increment an integer within an each loop?
Where does thi

Rails 3.2 undefined method `key?' for nil:NilClass
Web Development

For some reason I started to get this error after switching to Rails 3.2. I guess it has something to do with acl9 plugin, which I tried reinstalling, but nothing changed.


I moved the plugins to lib/plugins and added initializer to config/initializers but again, same error.


I looked for solution at acl9 repo on Github, but could not find anything there. Maybe it is not acl9 after all.


I have paperclip, acl9, authlogic installed.


NoMethodError (undefined method `key?' for nil:NilClass):
actionpack (3.2.1) lib/action_controller/metal/hide_actions.rb:36:in `visible_action?'
actionpack (3.2.1) li
Rails - why I'm getting undefined method `name' for nil:NilClass
26/4/2016 6:52 am Web Development

I'm displaying question by categories and each question has its own number. I made it like this(index.html.erb):

<% @categories.each do |category| %>
     <div id=<%= "box#{category.id}" -%>>
        <h1><%= category.name %></h1>
        <% category.questions.each_with_index do |question, i|
%>
            <ul class="question-list" style="display: inline;">
                <li><%= link_to (i + 1), show_path
%></li>
            </ul>
        <% end %>
     </div>
<% end %>

And when I click on question number I would like to show it like this(show.html.erb):

<div class="question-wrapper">
       <h1><%= @category.name %></h1>
       <div class="image left-align">
         <%= question_image_tag(question, :large) %>
       </div>
       <div class="question-text right-align">
        <%= @question.question_name %>
       </div>
       <p><%= @question.answer %></p>
 </div>

This is my controller:

def index
    @categories = Category.all
    @questions = Question.all
end

def show
    @categories = Category.all
    @questions = Question.all
end

Now, I'm getting undefined method `name' for nil:NilClass (also throws error for all methods in show.html.erb) and I can't resolve it.

Question: What should I do to resolve undefined method `name' for nil:NilClass?




HD Wallpapers
3D
3D Abstract
City
Celebrities
Indian Celebrities
Cars
Travel
Girls
Animals Birds
Movies
Sports
Black White
Nature
Planes
Anime
Food Drink
Dreamy Fantasy
Architecture
Games
Space
Holidays
Flowers
Love
Artistic
Baby
Beach
Bikes Motorcycles
Macro
Computers
Vector
Funny
Army
Textures
Brands
Misc
Music
Other
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .