Generating text fields in rails view -


let's suggest situation: eav data model (generic). exists entities table, attributes table , values table. i've made scaffoding of stuff. next, we're going values->new page. creates new value in values table. here have entity_id , attribute_id fields. , want add dynamic fields attributes table. so, in values controller in new action have this:

 def new     @value = value.new      @attribute = attribute.find(:all) #it not correct, search existing attributes entities, i'll fix later      respond_to |format|       format.html # new.html.erb       format.json { render json: @value }     end   end 

next going views->values->_form.html.erb , generation section here:

<% @attribute.each |attr| %>   <div class="field">     <%= f.label attr.name %><br />     <%= text_field_tag(controller.controller_name.singularize+'['+attr.name+']') %>   </div>     <% end %> 

look @ string: <%= text_field_tag(controller.controller_name.singularize+'['+attr.name+']') %> not "professional ruby" style. looks buggy , crap. (but works).

and finally, question: how make "professional ruby style", maybe must looks f.text_field attr.name (it does'nt works). how be? :)


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -