Either or both of these is wrong, since in the end I get a “Can’t find
an album without id”. There is a complicating issue, too, since if I
change the parameter name, I get “undefined local variable”.
Anyone got a quick example of the syntax for what must be a very
common and simple task???
Shouldn’t this be passed as “find_id”??? I guess I could have this
backward, will test. Maybe I’ll also try to log output to a file in the
controller, if rails will allow me to debug that way…
Anyway, really the best thing for me would be an example paralleling the
OP request.
Well, to be honest your first post looks correct by inspection. If you
are just posting the id though you do not necessarily need to
use :with. You can group all the items you want within the :url block.
Also, by saying ‘throw’, I mean that in your action in the controller
have ‘throw params’ as the first line and then when you try to access
that action it will output, to the screen, a trace that shows you what
parameters are coming across from the view. Very helpful. You can keep
throwing until you get the correct params coming across and then focus
on fixing or writing your action code.
Hmmm, I seem to be uncovering a more basic layer to my miscomprehension.
Thanks people, I think your input will come in handy, but bear with me
for a minute:
Here’s where I got to in trying to debug (just noticed stdout in the
controller is the server stdout, handy). Hence its long winded style:
and let me know if that solved the issue. It’s really bad/wasteful to
pull down all of your artists. Also, shorthand
Yeah, that is what I meant by “long winded”.
Why is there this issue with the name of a local, temporary variable?
If the scope is only a few lines, I might as well call it “x” (which is
why I think tmp is unambiguous: it indicates this variable is just
that, and nothing more than that)…Is this just the normal “pick
informative names” caveat, or is there more to it? Rails is slightly
scary…
Your “where =” line did not work – I may have mistyped it, but this
seems to do:
Most of all: Your help is much appreciated dude, THANKS!
ps. If you have a minute, here’s a little question about what I am
about to try: I have a list on one side with all the artists. A click
on a list entry will put all the artist’s albums in a div box on the
other side. Now, I want to add a menu up top with entries like “Sort
albums by size”, but I want that to apply only to the albums that are
currently displayed. I don’t want to produce the list again and sort it
(since I have some more complicated plans, like allowing the user to
build a custom list in the div box); I want to try and keep a global
variable ($shown) and process that back in the album controller.
Hopefully this is possible – any related tips brought to mind?
Nope. Your “good practice” is in fact more typing and more literal SQL
for what as far as I can see is no good reason at all. Take advantage
of Rails’ syntactic sugar and stick with the first version.