In rhtml, you have access to controller. I am trying to set an instance var
in my controller, then retrieve it in my form display. I know I could do
this through one of the hashes I have access to, but I''m trying to
understand why I can''t do it this way.
No matter what, when I try to output from my rhtml either
<%= controller.whynot || ''Unknown'' %> or <%=
controller.othermessage ||
''Unknown'' %> I don''t get the values I''m
setting. Here''s some of the ways I
try:
class ApplicationController < ActionController::Base
attr_accessor :othermessage
def whynot=(msg)
@msg = msg
end
def whynot
@msg
end
class AgentsController < ApplicationController
def show
othermessage = ''show set''
whynot=''jim''
@agent = Agent.find(params[:id])
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060602/bdb85216/attachment.html
Daniel N
2006-Jun-02 06:58 UTC
[Rails] Re: controller instance methods available in rhtml?
Hi Jim.
I think the controller makes it''s instance variables avaiIable to the
view. At least you can use it as though it does. Instead of using
<%= controller.whynot ...-%>
you would just use
<%= @msg | "Whatever" %>
Alternatively if you want to have these methods available in your
views then use
class ApplicationController < ActionController::Base
attr_accessor :othermessage
def whynot=(msg)
@msg = msg
end
def whynot
@msg
end
helper_method :whynot
...snip ...
That way you can use the whynot method directly in your views.
eg
<%= whynot || "Whatever" %>
Hope this helps ( & is strictly correct.)
On 6/2/06, Jim mack <jimmack1963@gmail.com> wrote:> In rhtml, you have access to controller. I am trying to set an instance
var
> in my controller, then retrieve it in my form display. I know I could do
> this through one of the hashes I have access to, but I''m trying to
> understand why I can''t do it this way.
>
> No matter what, when I try to output from my rhtml either
> <%= controller.whynot || ''Unknown'' %> or <%=
controller.othermessage ||
> ''Unknown'' %> I don''t get the values
I''m setting. Here''s some of the ways I
> try:
>
> class ApplicationController < ActionController::Base
>
> attr_accessor :othermessage
>
> def whynot=(msg)
> @msg = msg
> end
>
> def whynot
> @msg
> end
>
> class AgentsController < ApplicationController
>
> def show
> othermessage = ''show set''
> whynot=''jim''
> @agent = Agent.find(params[:id])
> end
>
>