ruby on rails // action cable chat tutorial error - ruby-on-rails

I followed the https://www.sitepoint.com/rails-and-actioncable-adding-advanced-features tutorial, but it says:
NameError in PersonalMessagesController#create uninitialized constant
PersonalMessage::NotificationBroadcastJob
after_create_commit do
conversation.touch
NotificationBroadcastJob.perform_later(self)
end
end
The above error appears when I submit, but when I go back I get a message.
So I deleted code:
after_create_commit do
conversation.touch
NotificationBroadcastJob.perform_later(self)
end
end
and tried to run it. I did not see the same error, but this time I can not chat live.
I followed the tutorial faithfully. I do not know why two problems arise. I need help.
my github : https://github.com/sangyeol-kim/stackoverflow_ask_ac2

Try fixing file name notifications_broadcast_job.rb -> notification_broadcast_job.rb

Related

Rails 5.2 to 6.0 upgrade issues with migration namespacing: uninitialized constant errors

Am having an issue with a NameError Exception: uninitialized constant error inside migrations that reference ActiveRecord models. These same issue are not present in the console, so I am a little stumped as to what is happening in the migration that is different from in the rails console.
Basically, my ActiveRecord models do not seem to be autoloading everything correctly.
Here is an example of a simple call that works in the console but raises an error in the migration:
migration(byebug)> Customer.all
*** NameError Exception: uninitialized constant Customer (call 'Customer.connection' to establish a connection)::Querier
Did you mean? Numerizer
nil
This same call, in the console, works.
Interestingly, if I first call another model that does load correctly (e.g., MyOtherThing.all), then if I next attempt to call to Customer.all no longer throws an error.
Just a little stumped as to where to begin to look for what's causing this. Thanks!
This ended up being a known issue:
https://github.com/rails/rails/issues/37748
Hopefully it will be fixed soon. And, part of my confusion had to do with dealing with byebug which was confusing me in terms of what was causing the real error.

Receiving Syntax Error When Adding Controller

New to RoR; I have received great help here.
Moving through a tutorial here, and I created a new controller. However, the config/routes file did not automatically update. Therefor, I made the edit myself and added get "static_pages/home" and get "static_pages/help". However, when I go to the url for the 'Home' page, I'm presented with and error stating:
SyntaxError in StaticPagesController#home
further stating:
/Users/coreymkimball/Canvi/sample_app/app/controllers/static_pages_controller.rb:2: syntax error, unexpected rails.root: /Users/coreymkimball/Canvi/sample_app
Can anyone give me a tip?
Actually i am not familiar in this .but you can refer this links.....hope this link will helpful.
Hartl Tutorial: 3.2 Error when i try and clean up my code
displaying two renders in staticpage home in rails 3

Rails doesn't log template errors in development mode

My Rails 3.2.9-app does not show any specific error information to me on errors in templates! It doesn't matter if I use haml or erb, I am always getting
"We're sorry, but something went wrong"
In fact, Webrick is in development mode and if there are errors in my models or controllers, I get the full ordinary error screen.
Examples
Example error in my helper-template ("#resource" does not exist, must be "resource"):
-> All I get is this lousy "We are sorry, but something went wrong"
<% #resource.errors.full_messages.each do |msg| %>
Example error in one of my controllers:
resposnd_to do |format|
-> undefined method `resposnd_to' for ...
I finally solved this problem!! All in all, I searched for more than 1 year, but now, i finally got the solution:
The problem is to use umlauts or blank spaces in the path of the rails project. If you move your rails project to a path without umlauts or blanks, the error message should be shown properly :-)!
Tested on ubuntu-machine, maybe this is important for this bug. This bug appears in rails 3.2.9, 3.2.13 and 3.2.14 definitely.
(consider_all_requests_local is activated of course, this never was the reason)

uninitialized constant - loading class issue?

So, I got mailer app/mailers/dynamic_mailer.rb and model app/models/email_message/outgoing.rb. There is method:
class EmailMessage::Outgoing < EmailMessage
...
def deliver_mail
l = ::DynamicMailer.email_message(self).deliver!
Rails.logger.info "SEND MAIL: #{l.inspect}"
update_attribute(:received_at, Time.now)
end
Locally (developement env) everything works fine. The problem occurs when I'm deploying app to server (staging env) and trying to send email form there. Delayed job prints:
[Worker(host:rdev pid:2279)] EmailMessage::Outgoing#send_email!
failed with NameError: uninitialized constant
EmailMessage::Outgoing::DynamicMailer - 11 failed attempts
It looks like a problem with loading classes on server. Removing double colons before class name fails.
Any help will be greatly appreciated.
Try to specify file with DynamicMailer obviously in file with your model like this require 'app/mailers/dynamic_mailer.rb'. Probably it can help to find necessary class.
Also I've noticed that in error message is mentioned send_email! method but you posted here def deliver_mail method. Whether I don't understand something or you're looking in wrong place.
I just forgot to restart delayed job daemon.
You can do it with capistrano, by adding gem 'daemons' to your Gemfile and updating receipes like that: http://cmar.me/2011/02/21/delayed_job-with-rails-3-and-capistrano/

Rails Guides - Step 11 - Multi Model Form - MassAssignmentSecurity error

I'm very carefully following the RailsGuide and it's working beautifully, until Step 11.
Adding Tags via a MultiModel form.
Once I've added the code I get this error:
ActiveModel::MassAssignmentSecurity::Error in PostsController#update
Can't mass-assign protected attributes: tags_attributes
Application Trace:
app/controllers/posts_controller.rb:65:in block in update'
app/controllers/posts_controller.rb:64:inupdate'
I've backed up and started over a few times to be certain it's not user error.
Can someone help me get past this step. I'm so close to done ! Then I can move on to Hartl's tutorial.
Thank you.
This is not your fault!
The deployed Getting Started guide hasn't been updated for the Rails 3.2.3 default of
# in config/application.rb:
config.active_record.whitelist_attributes = true
The fix is to add this to your Post model:
# in app/models/post.rb
class Post < ActiveRecord::Base
attr_accessible :tags_attributes
...
Incidentally, this whole section was removed from the source of the guide going forward, which you can find at https://github.com/rails/rails/blob/master/guides/source/getting_started.textile .

Resources