zaq
1
after playing with the DB interaction I’m moving on to doing some file
IO. but I’m completly lost as to where to put the code and how to call
it.
I’m trying to get a list of files in a directory and it’s not obvious to
me how to do this in Rails via a controller method.
so ruby code is
Dir.entries(“testdir”).last
and html code is
<%= Dir.entries(“testdir”).last %>
or
<% mylastfile= Dir.entries(“testdir”).last %>
<%= mylastfile %>
but how do I get this into the application controller
(./app/controllers/application.rb) so I can say anywhere
<%= mylastfile %>
?
zaq
2
zac elston wrote:
<% mylastfile= Dir.entries(“testdir”).last %>
<%= mylastfile %>
but how do I get this into the application controller
(./app/controllers/application.rb) so I can say anywhere
<%= mylastfile %>
class XController < Application
def stuff
@mylastfile= Dir.entries(“testdir”).last
end
end
stuff.rhtml
<%=mylastfile%>
not testet…
zaq
3
On Jan 27, 2006, at 11:54 AM, Mikkel B. wrote:
<%=mylastfile%>
not testet…
Or put it in a before filter in application.rb so it will be
available everywhere;
class ApplicationController < …
before_filter :get_last_file
attr_reader :mylastfile
protected
def get_last_file
@mylastfile = Dir.entries(“testdir”).last
end
end
Cheers-
-Ezra Z.
Yakima Herald-Republic
WebMaster
509-577-7732
[email protected]