Biju
Biju

Reputation: 978

When does the controller get loaded in Ruby on Rails?

I have a controller and a view for that controller. In the view, I render a lot of UI components like dropdowns, text fields etc.

There is a date_select in the UI which lists all the months and years from a certain table. By default, date_select selects the current month and current year in it.

There is a label just below the date_select which is supposed to show the number of business days in the month & year selected in the date_select.

I have written a JavaScript event handler (which calls a controller function as well) which is invoked when the user changes the value selected in the date_select). And the event handler calculates the number of business days (inside the controller function based on the working days present in another table) and displays it in the label below the date_select.

This event handler workds perfectly fine. But when the UI is loaded for the very first time, the label does not get populated at all. Looks like my controller is not getting invoked at all!

When the UI is rendered for the first time, won't the controller be invoked at all? If it does, will Rails be invoking the init method inside the controller first?

Upvotes: 0

Views: 134

Answers (1)

Talha Junaid
Talha Junaid

Reputation: 944

No, the controller action for calculating the business days won't be invoked. You need to send the ajax request to controller for calculating Business days on page load with current month and year params.

Upvotes: 2

Related Questions