c.id %> % end %>I have a code snippet in my list.html.erb file. It raises an exception 'Couldn't find Sub" name="description" /> c.id %> % end %>I have a code snippet in my list.html.erb file. It raises an exception 'Couldn't find Sub" />
3165

Couldn't find id=:all - Ruby on Rails

Question:

<ul id = "subjects"> <% Subject.find(:all).each do |c| %> <li><%= link_to c.name, :action => "show_subjects", :id => c.id %></li> <% end %> </ul>

I have a code snippet in my list.html.erb file. It raises an exception 'Couldn't find Subject with 'id'=all'. What's the problem in this case? The thing I want to do is to list all subjects as the hyperlinks.

Thanks for help.

Answer1:

The problem is you're using code that is ancient. Replace it with either of those two.

Subject.all.each do ...

or

Subject.find_each do ...

Explanation for error is that find automatically searches by id and :all is not a valid id and so it can't find anything and raises and exception.

Recommend

  • Giving right align to numeric data in datatables
  • How to make Rails do not ignore trailing slashes in the routes?
  • Custom routes with rails 3.1
  • Using Resque and resque_mailer to send emails raises Routing error
  • ember js subviews and didinsertelement event
  • Stalling at deallocate
  • Touch events over two dom elements?
  • JQuery Add class to certain list item
  • ng-repeat not working with table but works with list
  • How to Divide an array on c#?
  • Function JavaScript : on Menu CSS HTML
  • Can't delete li from to-do list
  • Bootstrap (v3.3.4) glyphicons not displayed in IE when refresh page (F5)
  • Implementing “partial void” in VB
  • Sending HTML Form Data to Spring REST Web Service
  • Parse a date string in a specific locale (not timezone!)
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • Using jQuery closest() method with class selector
  • How to get address from latitude and longitude android google map v2 [duplicate]
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • what is the difference between the asp.net mvc application and asp.net web application
  • Jquery - Jquery Wysiwyg return html as a string
  • Compare two NSDates in iPhone
  • How to get icons for entities from eclipse?
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Proper way to use connect-multiparty with express.js?
  • Load html files in TinyMce
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How to stop GridView from loading again when I press back button?
  • Turn off referential integrity in Derby? is it possible?
  • How can I remove ASP.NET Designer.cs files?
  • Add sale price programmatically to product variations
  • JaxB to read class hierarchy
  • Observable and ngFor in Angular 2
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal
  • How do I use LINQ to get all the Items that have a particular SubItem?