Rails Error When Trying To Mail to Multiple Users -
Whenever I'm trying to use the plugin to process a model for some time on the rail
When I try to use the mail-out process in my user model, I get the following error: Can someone tell me in the right direction of being wrong?
/var/lib/gems/1.8/gems/rails-2.3.5/lib/commands/runner.rb: 48: /var/lib/gems/1.8/gems/activesupport- 2.3.5 / lib / active_support / dependencies.rb: 380: IN`load_without_new_constant_marking ': / home / tnederlof / dropbox / ruby / daily_trailer / app / model / user .rb: 9: syntax error, unexpected tIDENTIFIER, expect' '' (Syntax error) @ User = find (all :: conditions => "# {workdays} sub" "" ")
My schedule. R.B is as follows:
each 1.day ,: at = & gt; '5:30 am' runner "user.mail_out" end
My user model is:
class user & lt; ActiveRecord :: Base acts_associative def self.mail_out day of the week = DateToday.frafttime ('% A'). Downcases @ user = find (all :: conditions => "# {workdays} all = t") users each {| U | UserMailer.deliver_mail_out (u)} End End
My User_mailer is:
Class UserMailer & lt; ActionMailer :: Base def mail_out (user) @recipients = {} users.each do | User | @recipients [user.email] = {: name = & gt; User.name} "no-reply@dailytrailer.net" ends with the theme "Watch the Day Trailer!" Body: user = & gt; End of user end
Migration:
create_table "users" ,: force = & gt; Is true T | T.string "email" t.date "birthday" t.string "gender" t.string "zipcode" t.datetime "created_at" t.datetime "updated_at" t.string "crypted_password" t.string "password_salt" t. String "persistence_token" t.string "mondaysub" ,: default = & gt; "F" ,: null = & gt; Wrong t.string "tuesdaysub" ,: default = & gt; "F" ,: null = & gt; False t String "wednesdaysub" ,: default => "F" ,: null = & gt; Wrong t.string "thursdaysub" ,: default = & gt; "F" ,: null = & gt; Wrong t.string "fridaysub" ,: default = & gt; "F" ,: null = & gt; Wrong t.string "saturdaysub" ,: default => "F" ,: null = & gt; Wrong t.string "sundaysub" ,: default = & gt; "F" ,: null = & gt; False end
Change this line
@ User = (All :: Terms = & gt; "# {Workday} SubTea")
to
@users = find For the rule, the key of the situations either takes the form of an array or value. If you are using the array then the first element of the array directly changes the "where" section in the SQL statement if you have any questions in it If you do not have the mark and if you have The symbols are replaced with elements in front of the array. For example, changing the above mark marking @users = find (: all ,: conditions => [" # {Weekday} sub =? ", 'T'] will be)
when 't' is a string
Using better question mark notation because It is more secure because you do not launch the string within your SQL string which is very harmful for app data for you May be factors.
You can type in a situation like your query the hash
@users = find (: all ,: conditions = & gt; {"# {Working days} sub" .to_sym = & gt; 'T'}) Most people prefer this more array instruction in other words, to see it as a way of rail to do this in such a way. And another point, by looking at your UserMailer # mailout method, you must
@ users.each {| U | UserMailer.deliver_mail_out (u)}
In your user In the mailout method, you can simply
UserMailer.deliver_mail_out (@users)
because you already have user alarms in your UserMailer # mailout Each user is removing the object and connecting them to the recipients.
Comments
Post a Comment