Created
September 27, 2008 13:43
-
-
Save geoffgarside/13328 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActionView | |
module Helpers | |
class FormBuilder | |
def submits(create_value = "Create", update_value = "Update", options = {}) | |
value = @object.new_record? ? create_value : update_value | |
submit(value, options) | |
end | |
end | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ A HAML form partial | |
- form_for current_object do |f| | |
= f.label :name | |
= f.text_field :name | |
= f.submits | |
/ Compiles to this if current_object.new_record? #=> true | |
<form action="/models" class="new_model" id="new_model" method="post"> | |
<div style="margin:0;padding:0"> | |
<input name="authenticity_token" type="hidden" value="blahblahblah" /> | |
</div> | |
<label for="model_name">Name</label> | |
<input id="model_name" name="model[name]" size="30" type="text" /> | |
<input id="model_submit" name="commit" type="submit" value="Create" /> | |
</form> | |
/ Compiles to this if current_object.new_record? #=> false | |
<form action="/models/1" class="edit_model" id="edit_model" method="post"> | |
<div style="margin:0;padding:0"> | |
<input name="_method" type="hidden" value="put" /> | |
<input name="authenticity_token" type="hidden" value="blahblahblah" /> | |
</div> | |
<label for="model_name">Name</label> | |
<input id="model_name" name="model[name]" size="30" type="text" value="Example" /> | |
<input id="model_submit" name="commit" type="submit" value="Update" /> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment