This happened to me several times, and I have not yet found an acceptable solution.
I have a form on the website’s home page that forms the points to another controller who actually does the data processing work. When the form submits successfully, another controller sends you back to the home page with a nice flash [: notice] message and finishes it.
When a verification problem occurs, it becomes a problem. I would like to show the home page with a form with validation errors. The naive solution, as a rule, mentions that you can display another template, but show the home page much more than the visualization of the template, it has a lot of functionality. The only way to visualize this template is to copy and paste the functionality into this other controller action or, possibly, remove all the functionality from the controller, which is not very nice.
Is there a better solution?
Update . I understand that people say that the actions of the controller should be less and call a different method, but in practice I do not see how to achieve it. I am going to post a real example from a website that I made.
There are two models and controllers: posts and comments. The message has many reasons. The message is shown as follows:
def index set_posts
The comment controller only has a create action:
def create @comment = Comment.new(params[:comment]) @comment.post = Post.find_by_slug params['post_id'] if not @comment.post
end
"What now?" parts for which I do not have a good solution.
source share