ruby - Rails Custom Validation With Request Params? -
Rail Nab,
I am trying to write a custom verification, Depending on what I have from this post request - in this post model, I want to make sure that no user was already posting on a topic, but to do this I must have a topic ID from the post request Should:
Class Post & lt; ActiveRecord :: Base ... Valid: user_already_posted, on :: create def user_already_posted Subject = Subject: where (id: params [: topicId]). First / some code that runs on the subject user and ensures that the user is not, however, I have learned that the parameter is not global and the model can not access it (I finally used Laurel, where this is not the case , So this is confusing to me). Are not Custom Ideas Required? Do I need to keep track of filters or do the controller perform valid work of my own?
I think you're doing a bit of a design problem here. You are creating a post
verifier, but the verification itself is not about the post
example. I mean, the ideal verifier has all the posts
attributes You should evaluate, using the built-in legalized code built into the ActiveRecord
or create custom ones, as you did, the code itself> . I believe that examining the terms of a class law
and obtaining all of its standards is more clear:
Models On the class method
def self.user_already_posted (topic_id, user_id) # Your talk expired
Use on the controller
can_create = post.user_already_posted (params [: topic_id], parameter [: user_id]
Comments
Post a Comment