I have simple rails application. Create, delete, edit posts. And I need to rate this posts.
Where to place rate function, in model or controller? and why?
I have simple rails application. Create, delete, edit posts. And I need to rate
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Usually this sort of thing plays out in both places. You’ll have a
ratemethod on the model, and you’ll have arateaction in the controller.Remember that it’s the controller’s primary function to receive requests, load the proper models, adjust them as necessary, and save the results. Often the models will implement the functionality required to facilitate this.
In the controller you’d make something like this:
In the model you’d have something like this:
Without a controller you can’t access the models, it has to go through that layer, and without a model you have no persistent data. They work together.