ani vadhavane
2006-Feb-13 08:23 UTC
[Rails] Executing ruby on rail program through address bar
I Want to run my ruby on rail application through address bar. i.e like: http://localhost/rail_program/first.rhtml. when i trying this it only executes html part but not executing rail part. Here is the code: <html> <head> <title>eruby example</title> </head> <body> <h1>Enumeration</h1> <ul> <%(1..10).each do|i|%> <li>number <%=i%></li> <%end%> </ul> <h1>Environment variables</h1> <table> <%ENV.keys.sort.each do |key|%> <tr> <th><%=key%></th><td><%=ENV[key]%></td> </tr> <%end%> </table> </body> </html> After executing this it not executes code within <% %> this tags. What is the problem? Help me. Thank you. -- Posted via http://www.ruby-forum.com/.
Gael Pourriel
2006-Feb-13 10:05 UTC
[Rails] Executing ruby on rail program through address bar
That would be because you dont call the views (RHTML files) directly from the URL, you call a controller action which will then "execute" the view and parse the RHTML file for ruby code. In you case you need to create a controller (if you dont have this already), create an action called "first" which doesn''t have to do anything but it will then render the file called first.rhtml and show the environment variables as you want to do. Since what you asking is very basic Rails, I strongly suggest you start by doing one of the Rails tutorials located here: http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html This will explain you the concept of MVC which you seem to have problem with... Gael On 13/02/06, ani vadhavane <vadhavane_anil@india.com> wrote:> > I Want to run my ruby on rail application through address bar. > i.e like: http://localhost/rail_program/first.rhtml. > > when i trying this it only executes html part but not executing rail > part. > > Here is the code: > > <html> > <head> > <title>eruby example</title> > </head> > <body> > <h1>Enumeration</h1> > <ul> > <%(1..10).each do|i|%> > <li>number <%=i%></li> > <%end%> > </ul> > <h1>Environment variables</h1> > <table> > <%ENV.keys.sort.each do |key|%> > <tr> > <th><%=key%></th><td><%=ENV[key]%></td> > </tr> > <%end%> > </table> > </body> > </html> > > After executing this it not executes code within <% %> this tags. > What is the problem? Help me. > > Thank you. > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >