Skip to main content
edited title
Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

How to refactor logic in the rails forms Building options for input fields

added formatting and a Ruby Tag
Source Link
Malachi
  • 28.7k
  • 11
  • 86
  • 188

In the _form_form partial I have a rather complicated logic which builds necessary options for input fields:

- input_html_params = dynamic_settings_select_options('#service-settings', settings_aps_instance_services_path(parent))

= simple_form_for [:aps, parent, resource] do |f|
  = f.input :service_status, :as => :readonly_label 
  = f.input :meta_service_meta_id, :collection => parent.meta_services, :value_method => :meta_id, :label_method => :name, :input_html => input_html_params
  = f.button :submit

The first problem which I see here is getting input_html_params to pass them into input of meta_service_meta_id because it already has a lot of parameters. Even this didn't help us to avoid long string to pass all parameters. What is best practice to avoid this complicity?

As you can see, extracting them to helper methods doesn't solve this problem, so I would like to hear something new.

In the _form partial I have a rather complicated logic which builds necessary options for input fields:

- input_html_params = dynamic_settings_select_options('#service-settings', settings_aps_instance_services_path(parent))

= simple_form_for [:aps, parent, resource] do |f|
  = f.input :service_status, :as => :readonly_label 
  = f.input :meta_service_meta_id, :collection => parent.meta_services, :value_method => :meta_id, :label_method => :name, :input_html => input_html_params
  = f.button :submit

The first problem which I see here is getting input_html_params to pass them into input of meta_service_meta_id because it already has a lot of parameters. Even this didn't help us to avoid long string to pass all parameters. What is best practice to avoid this complicity?

As you can see, extracting them to helper methods doesn't solve this problem, so I would like to hear something new.

In the _form partial I have a rather complicated logic which builds necessary options for input fields:

- input_html_params = dynamic_settings_select_options('#service-settings', settings_aps_instance_services_path(parent))

= simple_form_for [:aps, parent, resource] do |f|
  = f.input :service_status, :as => :readonly_label 
  = f.input :meta_service_meta_id, :collection => parent.meta_services, :value_method => :meta_id, :label_method => :name, :input_html => input_html_params
  = f.button :submit

The first problem which I see here is getting input_html_params to pass them into input of meta_service_meta_id because it already has a lot of parameters. Even this didn't help us to avoid long string to pass all parameters. What is best practice to avoid this complicity?

As you can see, extracting them to helper methods doesn't solve this problem, so I would like to hear something new.

deleted 9 characters in body; edited tags
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

In the _form partial I have a rather complicated logic which builds necessary options for input fields:

- input_html_params = dynamic_settings_select_options('#service-settings', settings_aps_instance_services_path(parent))

= simple_form_for [:aps, parent, resource] do |f|
  = f.input :service_status, :as => :readonly_label 
  = f.input :meta_service_meta_id, :collection => parent.meta_services, :value_method => :meta_id, :label_method => :name, :input_html => input_html_params
  = f.button :submit

The first problem which I see here is getting input_html_params to pass them into input of meta_service_meta_id because it already has a lot of parameters. Even this didn't help us to avoid long string to pass all parameters. What is best practice to avoid this complicity?

As you can see, extracting them to helper methodmethods doesn't solve this problem, so I would like to hear something new. Thank you!

In the _form partial I have a rather complicated logic which builds necessary options for input fields:

- input_html_params = dynamic_settings_select_options('#service-settings', settings_aps_instance_services_path(parent))

= simple_form_for [:aps, parent, resource] do |f|
  = f.input :service_status, :as => :readonly_label 
  = f.input :meta_service_meta_id, :collection => parent.meta_services, :value_method => :meta_id, :label_method => :name, :input_html => input_html_params
  = f.button :submit

The first problem which I see here is getting input_html_params to pass them into input of meta_service_meta_id because it already has a lot of parameters. Even this didn't help us to avoid long string to pass all parameters. What is best practice to avoid this complicity?

As you can see extracting them to helper method doesn't solve this problem, so I would like to hear something new. Thank you!

In the _form partial I have a rather complicated logic which builds necessary options for input fields:

- input_html_params = dynamic_settings_select_options('#service-settings', settings_aps_instance_services_path(parent))

= simple_form_for [:aps, parent, resource] do |f|
  = f.input :service_status, :as => :readonly_label 
  = f.input :meta_service_meta_id, :collection => parent.meta_services, :value_method => :meta_id, :label_method => :name, :input_html => input_html_params
  = f.button :submit

The first problem which I see here is getting input_html_params to pass them into input of meta_service_meta_id because it already has a lot of parameters. Even this didn't help us to avoid long string to pass all parameters. What is best practice to avoid this complicity?

As you can see, extracting them to helper methods doesn't solve this problem, so I would like to hear something new.

deleted 163 characters in body
Source Link
ka8725
  • 123
  • 4
Loading
Source Link
ka8725
  • 123
  • 4
Loading