I am pretty new to RoR and I am stuck on this problem and not even sure
how to troubleshoot it. The issue is that my index.rhtml is not
displaying any variables from my controller.
Controller (versions_controller.rb)
class VersionController < ApplicationController
def index
mydate = “20090521”
end
View (index.rhtml)
<%= @mydate %>
1
For some reason the view doesn’t see the variable. I also have a
def query
…
…
…
end
in the same controller and it works fine (feeding query.rhtml without
any issues).
I can even put garbage in the controller such as “a;lskjdfj” and it
doesn’t give me a compile error in the controller.
I am pretty new to RoR and I am stuck on this problem and not even sure
how to troubleshoot it. The issue is that my index.rhtml is not
displaying any variables from my controller.
Controller (versions_controller.rb)
class VersionController < ApplicationController
def index
mydate = “20090521”
end
Try this :
*
class VersionController < ApplicationController
def index @mydate = “20090521”
end*
On Fri, May 22, 2009 at 2:02 PM, Marek N.
Hi, thank you both for the quick reply. I did try that - but it still
does not pass the value to the view… Is there something outside of
the controller and view that could affect this?
To check that the view is interpreting this you could try <%= “value is
#{@mydate}” %>. If you see the fixed text then it is just that @mydate
is
not getting setup for some reason. Possibly a typo that you just can’t
get
your eye on.
What do you mean by “I can even put garbage in the controller such as
“a;lskjdfj” and it
doesn’t give me a compile error in the controller.”
Post the contents of versions_controller.rb, there must be something
wrong
there. Strip out some of the unneeded stuff if it is more than a few
tens of
lines. If you do change it, make sure that it still fails, and that
query
still works.
Colin
To check that the view is interpreting this you could try <%= “value is
#{@mydate}” %>. If you see the fixed text then it is just that @mydate
is
not getting setup for some reason. Possibly a typo that you just can’t
get
your eye on.
What do you mean by “I can even put garbage in the controller such as
“a;lskjdfj” and it
doesn’t give me a compile error in the controller.”
That is a good idea for a test case and the fixed text does appear, but
not the variable’s value. What kind of typo could cause this? The odd
thing is that I have a “def query” below it that is able to pass values
to “query.rhtml” without any issues…
As for your question, I have two rhtml files, index and query. If I put
meaningless junk in “def query” I get the following interpretation error
(as expected):
if I copy paste the same junk text into “def index”, it does not produce
an error (odd right?). This seems to indicate that
version_controller.rb is not interpreting the code in “def index” for
some reason, but is interpreting it in the “def query” which is directly
below it. This is at least consistent with why it is not showing the
value for @mydate. I don’t know enough about ruby to figure out what
could cause this sort of behaviour.
I don’t know, life will be easier if you stick to the conventions though
it
may not be the direct cause of the problem
The convention would be:
table versions
model version.rb, class Version
controller versions_controller.rb class VersionsController
views directory versions
Thank you Colin/Conrad, I appreciate your assistance. I am going to
read through that doc again (didn’t get everything the first time) and
see if I can see what is going on. I’ll post the solution if I find one
without starting over and renaming the project. Enjoy the weekend!