Do these two forms of 'render' have the same effect?
render 'contribute'
render :action => 'contribute'
Do these two forms of 'render' have the same effect?
render 'contribute'
render :action => 'contribute'
In short: Yes, they are the same.
However, sometimes passing a string will result in a call to render :file
or render :template
.
Here's the API docs for the render function
If we scroll down and click 'Show Source' we can see what it's doing under the hood.
Note the block starting at line 872:
872: elsif options.is_a?(String) || options.is_a?(Symbol)
873: case options.to_s.index('/')
874: when 0
875: extra_options[:file] = options
876: when nil
877: extra_options[:action] = options
878: else
879: extra_options[:template] = options
880: end
By looking at this code, we can determine that it is trying to be smart.
/
, (the when 0
case) then it will call render :file
/
at all, (the when nil
case) then it will call render :action
/
somewhere in the middle or end of the string (then else
case), then it will call render :template
Hope this answers your question satisfactorily :-)