forms - Rails Scaffold references with select input and Entity label with generators -


i'm trying scaffold app rails 4 , had little issue foreing keys, forms , entity names. here details:

rails g scaffold user_type name:string rails g scaffold user name:string pass:string user_type:references 

as can see there simple relationship 1:n between user_type , user. generates right scaffold on case. here image of form generated,

enter image description here

but want result of generator next form,

enter image description here

so first change want rails g scaffold generate, @ least e 1:n relationships select input. , i'm looking solution involves models label or something. need scaffold command generates this.

enter image description here

witch means entity user_type has name attribute has "presentation label".

i understand can create generator scratch, believe i'm missing options @ command line, because change tiny.

and can come solution involves inserting right code in each crud i'm planning use 150 tables database. help?

you can replace templates scaffold generator uses creating alternative templates in lib/templates/erb/scaffold folder in application root.

in case, want copy original _form.html.erb template , replace text field collection_select:

  <%- if attribute.reference? -%>     <%%= f.label :<%= attribute.column_name %> %><br> -   <%%= f.<%= attribute.field_type %> :<%= attribute.column_name %> %> +   <%%= f.collection_select :<%= attribute.column_name %>, <%= attribute.name.camelize %>.all, :id, :name, prompt: true  %>   <%- else -%> 

more details can read in my post on subject.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -