Sorry about the post I had an older version and a new version open in
Textmate and copied and pasted incorrect. This is my latest setup
which I started over from scratch using the standard restful index and
show for my views. I narrowed down my issue but not sure how to solve
just yet. So even with this instance @get_path out of my view still
get this error below. At least I'm understanding the error more now.
Error -- NameError (undefined local variable or method `directory_id'
for #<EditorialsController:0x2160fd8>):
Two Models
directory
def self.full_path(directory_id)
find(:all, :conditions => { :j15c_directory_id =>
"#{directory_id}" })
end
editorial Model
def self.date_range(from,to)
find(:all, :conditions => {:expiration_date => from..to },
:order => 'expiration_date DESC', :readonly => true)
end
One Controller
editorials_controller.rb
def index
@time_today = Time.now.ctime()
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @editorial }
end
end
def show
start_date = "#{params[:editorial][:"from(1i)"]}-
#{params[:editorial][:"from(2i)"]}-#{params[:editorial]
[:"from(3i)"] }"
end_date = "#{params[:editorial][:"to(1i)"]}-#{params[:editorial]
[:"to(2i)"]}-#{params[:editorial][:"to(3i)"] }"
@editorials = Editorial.date_range(start_date, end_date)
@get_path = Directory.full_path(directory_id)
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @editorial }
end
end
end
My Views
Index.html.erb
<h2>Input Date Range to form a Search</h2>
<p>
Todays Date and Time: <%= @time_today %>
</p>
<p>
Please Enter a Start date and End date range to search for
expiration dates.
</p>
<table>
<% form_for :editorial, :url => {:action => 'show' } do |form| %>
<tr>
<td>Start Date: <%= form.date_select :from %></td>
<td>End Date: <%= form.date_select :to %></td>
<td>Submit : <%= submit_tag "Search" %></td>
</tr>
<br />
<% end %>
</table>
Show.html.erb
<div id="expiration-list">
<p>Your search returned a Total of <%= @editorials.size %> file(s)</p>
<table>
<% for x in @editorials do %>
<tr valign="top" class="<%= cycle('list-line-odd', 'list-line-even')
%>">
<td><%= "File #{x.file_name} has an expiration date of
#{x.expiration_date} Directory ID: #{x.directory_id}" %>
******* This is the place I wanted to pass x.directory_id to
@get_path(x.directory_id) But it seems even without this I get an
error as soon as I hit submit from my index.html.erb page. My
thoughts were to just loop over the @get_path array and just grab one
field.
</tr>
<% end %>
<br>
</table>
</div>
Thanks again and apologize for the sloppy posting...