Ruby on Rails Why do I get the error: undefined method `email' for 69:Fixnum when trying to send an email? -



Ruby on Rails Why do I get the error: undefined method `email' for 69:Fixnum when trying to send an email? -

ok, in ror application have cinema scheme users have preferences, include saving favourite actor. trying when new cinema added, if users have of film's actors saved favourite email notifying them of film. @ min trying simplified version of 1 user emailed if cinema has actor liam neeson , email same 1 received when user sign's website (i have functionality working).

films_controller:

def create @film = film.new(film_params) if @film.save user = perference.where(actor: "liam neeson").pluck(:user_id).first if not user.blank? usermailer.welcome_email(user).deliver end redirect_to @film else render 'new' end end

user_mailer:

class usermailer < applicationmailer default from: 'no-reply@thorcinemas.com' def welcome_email(user) @user = user @url = 'http://localhost:3000/users/login' mail(to: @user.email, subject: 'welcome awesome site') end end

welcome_email.html.erb:

<!doctype html> <html> <head> <meta content='text/html; charset=utf-8' http-equiv='content-type' /> </head> <body> <h1>welcome thor cinemas, <%= @user.first_name %>!</h1> <p> have signed thor cinemas, username is: <%= @user.first_name %> <%= @user.last_name %>.<br> </p> <p> login site, follow link: <%= @url %>. </p> <p>thanks joining , have great day!</p> </body> </html>

and schema:

create_table "films", force: :cascade |t| t.string "title" t.string "synopsis" t.string "director" t.string "cast1" t.string "cast2" t.string "cast3" t.date "release_date" t.string "warnings" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "image_url" t.string "certificate_id" t.integer "category_id" t.integer "hours" t.integer "minutes" t.string "video_url" end create_table "perferences", force: :cascade |t| t.integer "user_id" t.integer "category_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.text "colour" t.text "actor" end create_table "users", force: :cascade |t| t.string "password_digest" t.string "role" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "first_name" t.string "last_name" t.string "house_no" t.string "street" t.string "town" t.string "postcode" t.string "email" t.date "date_of_birth" end

but next error:

nomethoderror in filmscontroller#create undefined method `email' 69:fixnum

i know there problems code @ minute, illustration isn't best practice have cast1, cast2, , cast3 in films table , there isn't validation ensure users emailed if favourite actor matches films's actor, trying send email @ min , deal these later.

can please help.

you passing integer (user_id) variable user controller mailer. need pass user object instead.

i can't see models, however, assuming have set proper associations, need update code finding user this:

user = perference.where(actor: "liam neeson").first.user

ruby-on-rails ruby ruby-on-rails-3 email ruby-on-rails-4

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -