I’m running Rails 2.3.5 on a hosted server, and cannot upgrade to 3.
I have one database, and it has a list of cartoons with id, date, and title. I can navigate through them using text links, and I also want to be able to navigate using a dropdown select, but I can’t get the select tag working. This isn’t a form to create a new element. Whereas the form shows up (being empty), the select tag does not show up, not even an empty select tag.
Here’s what I have:
*comics_controller.rb*
class ComicsController < ApplicationController
before_filter :get_all_comics
def get_all_comics
@comics=Comic.find(:all, :order => "date DESC")
end
def view
if params[:id].nil?
@comic=@comics.first
@prev=@comics[1]
else
@comic=Comic.find(params[:id])
@prev=Comic.find(:first, :conditions => ["date < ?", @comic.date],
:order => "date DESC")
@next=Comic.find(:first, :conditions => ["date > ?", @comic.date],
:order => "date ASC")
end
end
end
comics/view.html.erb
<% form_for :comics, :url => { :action => "view" } do |f|
f.select(:id,Comic.all,:prompt => true)
end %>
<img src="directory/<%= @comic.filename %>" />
<p class="title"><%= @comic.title %></p>
<p class="date"><%= @comic.date %></p>
<% unless @prev.nil? %>
<a href="<%= @prev.id %>">Previous</a>
<% end
unless @next.nil? %>
<a href="<%= @next.id %>">Next</a>
<% end %>
Edit: I suggest you also add
<%= submit_tag %>somewhere