Helper Method for Ordinary Startups Project.

I set my helper method in module StartupsHelper and used it in my app/views/startups/_form.html.erb which I rendered in startups/new.html.erb view. The name of my helper method is category_id_field and I passed @startup as an argument. This is exactly what I put in my form: <%= category_id_field(@startup) %>’ while defining the method in helpers. The method’s logic if the user chose the category ‘@startup.category_id’ user will enter the startup in the chosen category, without the dropdown select categories, which is the nested route — ‘http://localhost:3000/categories/1/startups/new'. However, if the user does not choose a category, the new form with the dropdown to choose from categories ‘select_tag “startup[category_id]”, options_from_collection_for_select(Category.all, :id, :name)’ and startups attributes, in the not nested route — ‘http://localhost:3000/startups/new' will present. def category_id_field(startup) if @startup.category_id hidden_field_tag “startup[category_id]”, startup.category_id else select_tag “startup[category_id]”, options_from_collection_for_select(Category.all, :id, :name) end end

Originally published at https://lkorchnoy.github.io on June 14, 2020.

--

--

Ludmila Korchnoy

Hello World! I’m a Full stack web developer experienced in Ruby and JavaScript frameworks. I graduated Flatiron School in October of 2020.