top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to control the length of Controller function in RoR

+2 votes
389 views

What you used to do when your controller function gets lengthy sometimes ? A way I found is just split the function. What is the real and Rails way to keep my code cleaner and maintainable.

posted Dec 2, 2013 by Garima Jain

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Use a service object. you can try to search "Service Object Rails" for more.

1 Answer

+1 vote

Probably some of the logic should be removed from the controller and put into methods in the model(s). So for example look at the code and anywhere you have a few lines that are to do with extracting data from the model and manipulating it in some way then consider writing a model method that implements that function.

You can also extract bits of code into private methods of the controller, but concentrate first on moving stuff into the models.

Finally, if there is a lot of code interpreting data encoded in the url then maybe the routes could be improved.

answer Dec 2, 2013 by Sonu Jindal
Similar Questions
+1 vote

I am using redmine and in welcome page, it displays all projects and subprojects. I want to hide all subprojects and display parent projects only. Any suggestion on how to achieve this?

+1 vote

I upload a image by giving only the url of the item, where the exact image should be stored in the storage(eg. AWS S3 bucket) for the future process.

Please give your suggestions/ideas to develop my thing.

+1 vote

I deployed one small app in heroku built on ROR, now I want to send mails. How is it possible can anyone give me a details how to do it.

0 votes

I have 4 tables from the first table, I took all data from the two columns and displayed it in the view. For each data, I have two text fields and the user is supposed to fill those data. Having filled data into the text field, how can I insert all the records into the second table using one form only?

+1 vote

I'm not looking for solution, but steps you would take to figure it out. I don't have experience with APIs and I figured that catching youtube data points and storing them in the database would be a great start?

Here is what I'm trying to accomplish: when I insert youtube video link into a form (create), then: thumb, link, title, date uploaded will get saved into the database as soon as I hit "submit." This will allow me to display these videos using the views.

...