SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    form_tag not working - error with login-form from sitepoint book

    Hi

    i read sitepoints book "Build your own ruby on rails web applications" by patrick lenz. it seems that there is a big mistake:

    At Page 244 there is the following Example-Code:

    Code:
    <% form_tag do %>
    
    	<p>Please log in.</p>
    	<p>
    		<label>Username:</label>
    		<%= text_field_tag 'login' %>
    	</p>
    	<p>
    		<label>Password:</label>
    		<%= password_field_tag 'password' %>
    	</p>
    	<p><%= submit_tag 'login' %></p>
    <% end %>
    When i request this page via URL i get nothing from this partial site.
    If i would type some letters before "<% form_tag", they would be rendered. But all letters from up to "<% form_tag" are'nt rendered.

    Please give me some hints what happenes here and how to fix this.

    My Versions:

    ruby: 1.8.6
    gem: 0.9.4
    rails: 1.2.5

    thank you for any help

    Kind Regards,
    J. Delnour

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code Ruby:
    <% form_tag do %>

    =>

    Code Ruby:
    <%= form_tag do %>

    The = tells Rails to insert the result of the form_tag into the HTML. It's likethe difference between <?php ... ?> and <?php echo ... ?> in PHP.

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, form_tag doesn't return a string like some of the other html helpers, so the equal sign isn't needed. In fact, it will throw an error if you include it.

    jdelnour: That is a weird problem - can you check you layout file? (/app/views/layouts/default.rhtml) - make sure there is a <&#37;= yield %> statement in there - could be along shot, but worth a look...

  4. #4
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    thanks for last posting.

    in layouts/application.rhtml there is the line <%= yield %> so this cant be the error here.

    but i found out the following:

    if i change the line

    Code:
    <% form_tag do %>
    to

    Code:
    <% form_tag '/account/login' do %>
    the login-form is rendered!

    so it seems that "form_tag" needs the Action-Parameter and cant work without it.

    can somebody agree oder disagree here?

    kind regards
    j. delmour

  5. #5
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    madpilot: you're right, you don't use an `=` sign if you pass a block to form_tag. Thanks

    j. delmour: form_tag works without the argument here. Check out the generated html (view source), do you see anything there? If not, start a new rails project and paste just the form code in that project. Does that work?

  6. #6
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im struggeling with the same problem, when i load the page all i get is th CSS layout with the shovell at the top.

    ive copied the files from the archive incase of a mistake but i still get the same.


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
  •