Frederick C. said the following on 11/12/07 04:23 PM:
All your controllers inherit from ApplicationController, so any
instance methods there are available from any instance of your
controllers
So in one controller I can’t access code from another controller?
I can’t even write
a = OtherController.new
to get to them.
What else can it use?
- app/helpers/application_helper.rb because if the above?
- app/helpers/_helper.rb ?
- any other helpers
Helper methods are (by default) only available in the appropriate view
So I can’t access the helper methods for a controller?
I seem to have helpers for each controller.
Can I only access code in them from the view corresponding to that
controller and not the controller?
What code in models can it use?
I think this question belies a misunderstanding of what is going on.
Trying to be comprehensive
You can from a controller call any of the class methods for a model
(eg find), and if you have an instance of a model then you can call
any of its public methods. This isn’t a rails question though - it’s
just the way the language is.
In view, what is the scope of the variables?
Do they have to be defined in the relevant controller?
The examples I look at, for example instiki, seem to have an awful lot
defined in the controller.
Instance variables are copied accross. That’s all
What about the main template?
What about “other” partials?
What methods can it use?
Helper methods (by default application_helper and the helper
associated with the controller, but you can specify extra modules/
functions)
I presume you mean libraries.
I understand ‘include’, but does that mean stuff in the views get access
to all code that’s on the PATH?
I ask this because a view, perhaps the template, may be accessing things
that don’t seem to appear in the controller. Am I seeing a side effect
of the search PATH?
I realise that there shouldn’t be code in the view, but decisions about
what to display seem OK, like this from instiki
<% if @page and (@page.name == 'HomePage') and
(%w( show published print ).include?(@action_name)) %>
<%= h @web.name %>
<% elsif @web %>
<%= @title %> in <%= h @web.name %>
<% else %>
<%= @title %>
<% end %>
<%= @show_diff ? ' (changes)' : '' %>
Fred
Just the ones for the the controller?
What about methods for the models?
What about things defined in the libraries?
–
Few problems cannot be solved by proper application of high explosives.