Rails Links to scaffolding with selected input and Entity label with generators

I am trying to lift an application with Rails 4 and I had this little problem with Entity keys, forms and names. Here are a few details:

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

As you can see, there is a simple 1: n relationship between user_typeand a user. It generates the right scaffold in this case. Here is an image of the formed form,

enter image description here

But what I want as a result of the generator is the following form,

enter image description here

So, the first change I want from rails g scaffoldis to generate at least an e 1: n relationship with the selected input. And also I'm looking for a solution that includes Models with labelor something like that. I need scaffold commandone that finally generates this.

enter image description here

, Entity user_type name .

, , , , .

, CRUD, 150 . ?

+4
1

, , lib/templates/erb/scaffold .

_form.html.erb 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 -%>

.

+6

Source: https://habr.com/ru/post/1524747/


All Articles