Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1071917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:46:45+00:00 2026-05-16T20:46:45+00:00

I want to make this thing more generic. <%= form_for :page, :url => {

  • 0

I want to make this thing more generic.

<%= form_for :page, :url => { :action => :create } do |form| %>
<div class="tabs">
  <ul>
  <% languages.each_with_index do |lang, i| %>
    <li><a href="#tabs-<%= i+1 %>"><%= lang %></a></li>
  <% end %>
  </ul>

  <% languages.each_with_index do |lang, i| %>
  <div id="tabs-<%= i+1 %>">
  <fieldset class="inputs">
  <ol>
    <li><%= form.label fname("title", lang), "Title" %>
    <%= form.text_field fname("title", lang), :size => 80, :class => "text" %></li>

    <li><%= form.text_area fname("content", lang), :cols => 40, :rows => 10 %></li>

    <li><%= form.label fname("published", lang), "Publish?" %>
    <%= form.check_box fname("published", lang) %></li>
  </ol>
  </fieldset>
  </div>
  <% end %>
</div>

It generates a tab and form-fields for each language. I need this tabs for other forms too, so I want to extract the “logic” into a helper. Problem is, that I dont know how.

<%= form_for :page, :url => { :action => :create } do |form| %>
<% language_tabs do |lang| %>
   <li><%= form.label fname("title", lang), "Title" %>
   <%= form.text_field fname("title", lang), :size => 80, :class => "text" %></li>

   <li><%= form.text_area fname("content", lang), :cols => 40, :rows => 10 %></li>

   <li><%= form.label fname("published", lang), "Publish?" %>
   <%= form.check_box fname("published", lang) %></li>
<% end %>
<% end %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:46:45+00:00Added an answer on May 16, 2026 at 8:46 pm

    looks like a good candidate for a partial template. http://api.rubyonrails.org/classes/ActionView/Partials.html

    I just realized what you really want 🙂 So you can combine partials and block helpers, look at:

    http://snippets.dzone.com/posts/show/2483

    I’ll post a solution in 10mins 😉

    So here comes your solution:

    1) application_helper.rb (or any other suitable helper file) add this:

    def language_tabs(languages, &block) 
      tabs = []
      languages.each_with_index do |lang, i|
        tabs << render(:partial => 'tab', :locals => {:body => capture(lang, &block), :lang => lang, :i => i })
      end
    
      render(:partial => 'langtabs', :locals => {:languages => languages, :tabs => tabs})
    
    end 
    

    2) Partial _langtabs.html.erb

    <div class="tabs">
      <ul>
      <% languages.each_with_index do |lang, i| %>
        <li><a href="#tabs-<%= i+1 %>"><%= lang %></a></li>
      <% end %>
      </ul>
    
      <% tabs.each do |cTab| %>
        <%= cTab %>
      <% end %>
    
    </div>
    

    3) partial _tab.html.erb

    <div id="tabs-<%= i+1 %>">
    <fieldset class="inputs">
    <ol>
      <%= body %>
    </ol>
    </fieldset>
    </div>
    

    4) Your actual form (note: there’s a variable called @languages in my example!) :

    <%= form_for :page, :url => { :action => :create } do |form| %>
      <% language_tabs @languages do |lang| %>
         <li><%= form.label fname("title", lang), "Title" %>
         <%= form.text_field fname("title", lang), :size => 80, :class => "text" %></li>
    
         <li><%= form.text_area fname("content", lang), :cols => 40, :rows => 10 %></li>
    
         <li><%= form.label fname("published", lang), "Publish?" %>
         <%= form.check_box fname("published", lang) %></li>
      <% end %>
    <% end %>
    

    Grüsse

    Simon

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make this kind of query: create procedure something @name varchar(13) as
I have an element, like this: <div id=navleft> </div> I want to make this
I want to make a form like this, and i want to post the
I want to make this specialized w/o changing main. Is it possible to specialize
I don't want to make this into a which is better... MVC or WebForms
I want to make something like this... :LoopBegin if ???? goto End some other
Let's make this very easy. What I want: @array = qw/one two one/; my
I want to make the line marked with // THIS LINE SHOULD BE PRINTING
I have this code that I want to make point-free; (\k t -> chr
I want to make a dropdown menu like delicious has at this http://delicious.com/search?context=all&p=sql&lc=1 page.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.