In my model I have:
class ArticleComment < ActiveRecord::Base
include Rakismet::Model
validates :text, :presence => true
belongs_to :article
belongs_to :user
comment, permalink, request, username, email, text, remote_ip,
user_agent, referrer = nil
def init_sp(comment_, permalink_, request_, username_, email_, text_)
comment, permalink, request, username, email, text =
comment_, permalink_, request_, username, email_, text_
remote_ip = request_.remote_ip
user_agent = request_.env["HTTP_USER_AGENT"],
referrer = request_.env["HTTP_REFERER"]
end
rakismet_attrs author: username, author_url: permalink, author_email: email,
content: text, permalink: permalink, user_ip: remote_ip,
user_agent: user_agent, referrer: referrer
binding.pry
end
and in controller:
def create
@article_comment = ArticleComment.new(article_comment_params)
@spam = @article_comment.init_sp(@article_comment, params[:permalink],
request, username, email, article_comment_params[:text])
if !@article_comment.spam?
....
So I need to set up field's like ip, user_agent, text in controller, how could I do this?
Now I see that my value's are nil ( why?
How to set rakismet_attrs value's with help of controller?
When you call
article_comment_paramsthe values are nil because Rails 4 uses strong parameters by default, so the parameters are filtered out because you do not explicitlypermitthem.In the method
article_comment_paramsyou need to explicitly permit every parameter you want to whitelist / allow through the controller.Change your
article_comment_paramsmethod to include thepermitmethod:I don't know exactly what params you want to allow, so make sure you go through the list and include every parameter you need.
The difficulty with this issue should be resolved when you whitelist the parameters using the method described above.