Trying to put in my controller
Flash[:notice] = "<%= #{link_to 'edit', :action => 'edit'} =>"
but, I get a "undefined method link_to" error.
I would think that the :notice code would be rendered in the view,
which should work and not get the "undefined method" error, but this
does not seem the case. It appears that its rendered in the controller
where I guess this method is undefined. Is there a way to force the
rendering to occur in the view? Or am I totally missing something
here?
flash[:notice] is not something magic, it's just a hash which persists (in the session) across requests, and obviously that srting is just a regular old string, so interpolation happens exactly as it would normally. There's no rendering going on here.
There are various howtos on the web about using view helpers from your controllers, which would be one way of solving your problem.
Fred
Fred,
flash[:notice] is not something magic, it's just a hash which persists
(in the session) across requests, and obviously that srting is just a
regular old string, so interpolation happens exactly as it would
normally. There's no rendering going on here.
Understood. But I guess I am confused as to why this would not work,
since if I place this exact same code:
"ink_to 'edit', :action => 'edit'}"
in the resulting view, it has no problem finding this method and
displaying it. So it seems that the utilization of this method
"link_to" is happening before it even gets to the view???
There are various howtos on the web about using view helpers from your
controllers, which would be one way of solving your problem.
I must admit that I have not utilized these yet, so I'll do some more
homework.
Thanks!
Fred,
flash[:notice] is not something magic, it's just a hash which
persists
(in the session) across requests, and obviously that srting is just a
regular old string, so interpolation happens exactly as it would
normally. There's no rendering going on here.
Understood. But I guess I am confused as to why this would not work,
since if I place this exact same code:
"ink_to 'edit', :action => 'edit'}"
in the resulting view, it has no problem finding this method and
displaying it. So it seems that the utilization of this method
"link_to" is happening before it even gets to the view???
Yes. It's just an ordinary string you've got there so the
interpolation happens when it is declared
Or to put things another way. if you had
a = " #{Time.now} "
then Time.now gets evaluated straight away. the fact that you've
written flash[:notice] instead of a and stuff involving link_to
instead of Time.now changes nothing.
I'm guessing you thought the use of <%= in your string would make
something special happen, but that's not the case.
Fred