0

I have old HTML code with html and css..

<form action="login" method="post"> 
<div class="field">
   <label for="username">Username</label>
   <input type="text" class="text" id="username" name="username" value="just click login !"/>
</div>
<span class="fright">
<button class="button" type="submit"><strong>Log In</strong></button>
</span>
</div>

How can i convert this code to decent rails code? I came up with this, but it ain't right :-( :

<% form_for :user, @user,  :url => { :action => "login" } do |f| %>
<% div_for f, :class => "field text" do  %>
        <%= f.text_field :username %>
        <%= f.password_field :password, :class => "field text" %>
    <% end %>
    <span class="fright">
    <%= submit_tag '<strong>Inloggen</strong>', :class => "button",:disable_with => 'verwerken...' %></span>
<% end %>

I'm having problems with the

 <strong>Inloggen</strong> 

And with the

<% div_for f, :class => "field text" do  %>

2 Answers 2

1

submit_tag generates the text as the value attribute of the input tag.

submit_tag "Edit this article"
# => <input name="commit" type="submit" value="Edit this article" />

So adding strong to that text is not gonna work, and it generates a <input> and it appears you want a <button>. So just use html here as well.

<button class="button" type="submit"><strong>Log In</strong></button>

Since you dont need to alter this based on any variables, you don't need to render it with ruby.


And you don't need div_for based on your target HTML. Simply use . No reason to make your template render that with ruby.


Lesson here is don't try too hard. Sometimes plain HTML is fine.

1

Try something like this:

<% form_for :user, @user,  :url => { :action => "login" } do |f| %>
  <div class="field">
    <%= f.text_field :username %>
    <%= f.password_field :password, :class => "field text" %>
  </div>
  <span class="fright">
    <%= submit_tag 'Inloggen', :class => "button strong",:disable_with => 'verwerken...' %>
  </span>
<% end %>

I moved <strong> from submit_tag description to class, because I'm not sure if submit tag will accept it. So you need to define .strong class in your css.

4
  • It's not working, sorry. I tried it and it's the same effect as my previous used code
    – NicoJuicy
    Feb 8, 2010 at 17:01
  • There are no errors. Only the lay-out isn't correct. I need: - The text from the button in <strong></strong>, because of css button design. Below is my css from <strong> .button strong { background:url(../images/sprite.png) no-repeat 100% -150px; display:block; height:30px; line-height:28px; padding-right:10px; white-space:nowrap; } so changing the strong class in css won't work for my layout. -Also, the textboxes class = "field text", it's not the elements who are encapsulated with this class. It is the design of the form-elements.
    – NicoJuicy
    Feb 8, 2010 at 19:29
  • Ok, I got your point now. As I googled around it seams that Rails doesn't provide any helpers to create <button>, so you can write your own or just don't write it in RoR - leave it as it was in html. It won't be bad to do so :)
    – klew
    Feb 8, 2010 at 22:12
  • Don't know how to write it, so i'll leave it in html. Thank you, your comment is the answer, so i'll accept above ;) Thanks!
    – NicoJuicy
    Feb 8, 2010 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.