SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wow. Different parameters for render_* methods in helpers and controller?

    Hi,

    Well in my attempt to write a simple CMS, I have been thrown into a wild goose chase! multiple times! Luckily, I found and caught the wild goose My experience deals with the methods (maybe there are more) of render_file and render_template.

    First, I placed a render_file call into a helper like so:
    Code:
    render_file("#{RAILS_ROOT}/app/types/" + @item.content_type.to_s + '/' + name + '.rhtml')
          produces
          No rhtml, rxml, or delegate template found for ./script/../config/../app/types/basic/item.rhtml
    As you can see, thats not right. (Yes it does exist, as you'll see in a second). So I went looking around for awhile and couldn't find a solution so I decided to use render_template which by looking at the source of render_file, I could see it called. So I did this:
    Code:
    render_template('rhtml', nil, "#{RAILS_ROOT}/app/types/" + @item.content_type.to_s + '/' + name + '.rhtml')
    Which works. What? Yea. I just thought I was passing incorrect parameters and thought nothing of it. So I continued programming until I realized, itd be much easier to put the render calls into the controller since the controller must call it too and the helper can call the controller, but not vice versa. So I copied and pasted my method into my controller, which produced the infamous:
    No rhtml, rxml, or delegate template found for ./script/../config/../app/types/basic/item.rhtml
    What?!!! I copied the code exactly! So then I thought "what about giving render_file another go" so I put the exact code that didn't work before (see above) into the controller's method. Guess what?
    It worked

    Still, I didn't think much of it... just that it was strange. Then I stumbled upon a google cache of the APIs and saw that the parameters for render_template were different. Just to let you all know, my rails is updated to the lastest version, i promise. I just updated a few days ago. So my hypothesis is that somehow the old method is being used from the controller, and the new from the helper.

    Is that possible? If so, why? If not, what else could be happening to explain these occurences?

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured this out after... 6 days. Again, I figured this out by chance but basically, when a helper method is called, you RETURN the content to be displayed. And when you call a page, you render it. Certain render functions return the text while others render it to the page.

    Confusing. I'm still working it all out but I am sure that is the reason (ive tested).


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •