I'm starting Rails and Ruby for a short time. But I try to make it the cleanest way I can. So, in an attempt to clean my view I try to custom my FormBuilder. Like this :
# /config/initializers/custom_form_builder.rb
class ActionView::Helpers::FormBuilder
# My test form function
def test label
return "Whatever I want to do ..."
end
end
And then I can use it like this :
# /app/views/test/test.html.erb
...
<%= form_for test, :html => {:multipart => true} do |f| %>
...
<%= f.test(":-)") %>
...
<% end %>
...
This part works perfectly fine.
However, what I want to do know is to create form views containing the HTML code I want to use in my forms. This way, I can store the HTML of all my form in a pseudo-HTML way, and structured within my directories.
So I created a template :
# /app/views/forms/test.html.erb
<input type="text" value="test" />
And I tried to render it from my FormBuilder :
# /config/initializers/custom_form_builder.rb
def test label
render "forms/test"
end
And I added it to my routes :
# /config/routes.rb
match "/forms/test" => "forms#test"
So my questions lies here :
- Do I try to make it work the wrong way ?
- Is it possible to render from my FormBuilder Class ?
- Is there some useless code in there ?
Thanks in advance,
John