rails g scaffold creates strange form

In this form created by the scaffold generator all the field names are prepended with the table_name plus underscore What causes this to happen in rails 5.1.7

<%= form.label :start_date %> <%= form.datetime_select :start_date, id: :auction_listing_start_date %>

Take a look at the `form_with` method at the top of the form. What is the variable declared inside the block at the end of that line? That's what you're seeing here, nothing more. The declared variable for the form builder is what precedes every form helper method inside the block. In the past, it was traditionally `f`. In never versions, they use `form`. It doesn't matter what you use, as long as it is consistent throughout the form_with or form_for block.

Walter

I mean the field names Instead of just fieldname it's tablename_fieldname

You're looking at the id. If you look at how the form renders in a browser, the name property will be the usual Rails nested format:

<input type="date" name="auction_listing[start_date]" id="auction_listing_start_date">

I can't be bothered to write out an entire set of select tags, just imagine if datetime_select was written as date_tag. That's how it would render.

Walter

Heh, yea you’re right What versions of rails add the id for scaffold generator?

Can you help me with my other problem, favicon with webpacker? It’s another post Webpacker complains it can’t find a compiled favicon.ico in manifest.json I assume this means I’m missing an entry in package.json for favicon.ico but I actually followed a tutorial called “bundle your favicons with webpacker” https://medium.com/tech-angels-publications/bundle-your-favicons-with-webpack-b69d834b2f53 I did exactly what the tutorial said but I get this error

You're looking at the id. If you look at how the form renders in a browser, the name property will be the usual Rails nested format:

<input type="date" name="auction_listing[start_date]" id="auction_listing_start_date">

I can't be bothered to write out an entire set of select tags, just imagine if datetime_select was written as date_tag. That's how it would render.

Walter

> > I mean the field names Instead of just fieldname it's tablename_fieldname > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonra...@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f6241dbd-793c-4efc-b698-eb59d5ed22aa%40googlegroups.com.

Can you help me with my other problem, favicon with webpacker? It's another post Webpacker complains it can't find a compiled favicon.ico in manifest.json I assume this means I'm missing an entry in package.json for favicon.ico but I actually followed a tutorial called "bundle your favicons with webpacker" Bundle your favicons with Webpack | by Olivier Gonzalez | Tech-Angels publications | Medium I did exactly what the tutorial said but I get this error

I've never used webpacker for anything serious, and every time I have used it trivially, I have not configured anything manually. I would second the other advice you got in the original thread -- just ensure that webpacker doesn't know anything about your favicon, and let your Web server host it normally.

Any regular (web-readable) file in the /public directory of your project will be served by your Web server without any interference by Rails or any form of its asset pipeline. Don't use the tag generator in your application.html.erb file, just use a normal meta tag as if you were hand-coding static HTML. The correct href to use is '/favicon.ico', and that maps directly to /path/to/your/application/public/favicon.ico.

Walter

You're looking at the id. If you look at how the form renders in a browser, the name property will be the usual Rails nested format:

<input type="date" name="auction_listing[start_date]" id="auction_listing_start_date">

I can't be bothered to write out an entire set of select tags, just imagine if datetime_select was written as date_tag. That's how it would render.

Walter

> > I mean the field names Instead of just fieldname it's tablename_fieldname > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonra...@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f6241dbd-793c-4efc-b698-eb59d5ed22aa%40googlegroups.com.

Heh, yea you're right What versions of rails add the id for scaffold generator?

I believe this happened in 5.2, and it was a fix to a regression introduced in 5.1, when they switched the form generator from form_for (which already had automatic IDs generated by the tag helpers) to form_with, which removed those.

Rather than restoring the magical automatic ID attributes, the scaffold generator was updated to include the id: 'whatever_attribute' directive in the individual tags, and the tag helpers were left alone.

Previously, if you wanted to suppress the ID for a form element (say, if you needed to have two or more identical elements on the page -- think: a bunch of checkboxes for the same attribute), you would have to pass id: nil or id: false (one of those) to the helper. Now, that's the default behavior, and if you want an ID at all, you have to tell it what you want that ID to be. I'm not sure where the edge case is here; whether it's more common to want no ID, or to have a nice unique one generated for you for free. It's clear what the framework designers chose.

Walter

Sorry, I meant link tag, not meta tag.

Walter

How do I ensure that webpacker doesn’t know anything about my favicon I removed the favicon lines in application.js and renamed favicons.js to favicons.js.renamed and than ran rake webpacker:compile (not that i know what that’s supposed to be for) but still the app is complaining favicon.ico can’t be found in manifest.js

I have no idea. This is not something I've encountered in my own apps, perhaps there is another manifest somewhere that is requiring it, since it was once added and attempted to compile.

I've just updated to Rails 6.0.2, in Ruby 2.6.5. Run rails new test-6, and after a mighty pause for gem compilation and so forth, 'Webpacker successfully installed :trumpet: :cake:' appears on my screen.

rails g scaffold Foo bar baz boo

And now, this:

rake webpacker:compile Compiling... Compiled all packs in /Users/waltd/Documents/sandbox/test-6/public/packs Hash: 60efe71c97239d74f7f6 Version: webpack 4.41.2 Time: 3521ms Built at: 12/15/2019 12:45:40 PM                                         Asset Size Chunks Chunk Names        js/application-6297f63bc162c780afc3.js 69.2 KiB 0 [emitted] [immutable] application     js/application-6297f63bc162c780afc3.js.br 15.3 KiB [emitted]
    js/application-6297f63bc162c780afc3.js.gz 17.7 KiB [emitted]
   js/application-6297f63bc162c780afc3.js.map 205 KiB 0 [emitted] [dev] application js/application-6297f63bc162c780afc3.js.map.br 43.9 KiB [emitted]
js/application-6297f63bc162c780afc3.js.map.gz 51 KiB [emitted]
                                manifest.json 364 bytes [emitted]
                             manifest.json.br 127 bytes [emitted]
                             manifest.json.gz 142 bytes [emitted]
Entrypoint application = js/application-6297f63bc162c780afc3.js js/application-6297f63bc162c780afc3.js.map [0] (webpack)/buildin/module.js 552 bytes {0} [built] [1] ./app/javascript/packs/application.js 742 bytes {0} [built] [5] ./app/javascript/channels/index.js 205 bytes {0} [built] [6] ./app/javascript/channels sync _channel\.js$ 160 bytes {0} [built]     + 3 hidden modules

No mention of missing anything, no mention of favicon in the context of JS at all.

No mention of favicon in the page head, either. So I remedied that:

<link rel="icon" href="/favicon.ico">

And running this in rails server again gives me no issues with JS and favicon.

So clearly, your mileage varies, and that means that something you did with webpacker differs from what I did with webpacker. Since I did as little as possible, maybe you did too much one time, and it got stuck that way. Nuke the whole thing from orbit, and try again somewhere else, as Ripley might say.

Walter