我有一个IOS应用程序,我想通过Mandrill发送电子邮件.我试图实现这一点,但它不起作用,我混淆了自己.
当按下按钮从IOS应用程序发送电子邮件时,我记录此错误消息:
{"status":"error","code":-1,"name":"ValidationError","message":"You must specify a key value"}
Run Code Online (Sandbox Code Playgroud)
我的代码是:
NSString *post = [NSString stringWithFormat:@"{\"key\": \"abcdefg123456\", \"raw_message\": \"From: me@mydomain.com\nTo: me@myotherdomain.com\nSubject: Some Subject\n\nSome content.}"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"https://mandrillapp.com/api/1.0/messages/send-raw.json"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSLog(@"Post: %@", post);
NSURLResponse *response;
NSData *POSTReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
NSString *theReply = [[NSString alloc] initWithBytes:[POSTReply bytes] length:[POSTReply length] encoding: NSASCIIStringEncoding];
NSLog(@"Reply: %@", theReply); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用actionmailer在发布新评论时通知我,但我一直收到错误消息:
uninitialized constant CommentsController::CommentMailer
Run Code Online (Sandbox Code Playgroud)
评论已添加到我的数据库中,可以查看.我也在使用设计,它的电子邮件功能正常.
我的评论邮件:
class CommentMailer < ActionMailer::Base
def newcomment(comment)
mail(:to => "admin@example.com", :subject => "New Comment")
end
end
Run Code Online (Sandbox Code Playgroud)
和我的控制器部分:
def create
@comment = Comment.new(params[:comment])
@comment.user_id = current_user.id
respond_to do |format|
if @comment.save
CommentMailer.newcomment(@comment).deliver
format.html { redirect_to @comment, notice: 'Comment was successfully created!' }
format.json { render json: @comment, status: :created, location: @comment }
else
format.html { render action: "new" }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
end
end
Run Code Online (Sandbox Code Playgroud) 我正在寻找限制我的用户每天发布超过两次,每周不超过5个帖子.我有一个用户和帖子模型/控制器.
我一直在看这些问题,但它们并不是我想要的.
错误@ 20:44 13/03/2012,来自KandadaBoggu的代码
NoMethodError in PostsController#create
undefined method `beginnning_of_day' for 2012-03-13 20:36:11 +0000:Time
Run Code Online (Sandbox Code Playgroud)