3

i was a bit experimenting in my rails app.i tried to use render :template in erb file .i got an error.After that i changed it to render :partial and it ran successfully as i was expecting.i am wondering why i got this error.i tried to google but i got no major source that points out the difference between the two.Does the two behave differently at controller level and view level.if yes then why?

  • 2
    I think read the following link you get your answer. http://guides.rubyonrails.org/layouts_and_rendering.html – urjit on rails Jul 17 '13 at 11:01
  • thanks @urjit rajgor..i will go through and clear my concepts. –  Jul 17 '13 at 11:42
  • I think the main difference between `render` and `render partial` is `render` does not accept additional local variables but `render partial` does. For more info you can see http://stackoverflow.com/questions/16822775/difference-between-render-and-render-partial-and-yield – Engr. Hasanuzzaman Sumon Sep 29 '15 at 07:10

1 Answers1

4

The render :partial looks for the file name to be proceeded by an underscore while the template does not:

  render partial:'example'

looks for _example.html.erb

while:

 render template: 'example'

looks for example.html.erb

There may be other issues, but odds are this is why you recieved the error based on it working once you made the change. Hope this helps...

MechDog
  • 508
  • 7
  • 18