I'm trying to test how ActionMailbox works on localhost using:
http://localhost:5000/rails/conductor/action_mailbox/inbound_emails
It works fine until I try to add an attachment. Then I receive an error:
ActionController::UnpermittedParameters (found unpermitted parameter: :attachments):
actionpack (6.1.3.1) lib/action_controller/metal/strong_parameters.rb:973:in `unpermitted_parameters!'
actionpack (6.1.3.1) lib/action_controller/metal/strong_parameters.rb:604:in `permit'
actionmailbox (6.1.3.1) app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb:23:in `new_mail'
actionmailbox (6.1.3.1) app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb:17:in `create'
I was trying to add :attachments to permitted parameters in line 23 of inbound_emails_controller.rb but with no effect :/
I have no idea why it doesn't work and nobody else found this bug :(
Related
The following form intends to generate an XHR response
<% articlediscounts_for_article = #articlediscounts.where(article_id: article.id).first %>
<%= form_with(scope: articlediscounts_for_article, url: user_discount_users_path, local: false, method: :post) do |form| %>
the action processes
Processing by UsersController#user_discount as JS
and generates expected results, but fails in the rendering process, complaining about (with initial stack)
ActionController::UnknownFormat (UsersController#user_discount is missing a template for this request format and variant.
request.formats: ["text/javascript", "*/*"]
request.variant: []):
actionpack (6.1.3.2) lib/action_controller/metal/implicit_render.rb:42:in `default_render'
actionpack (6.1.3.2) lib/action_controller/metal/basic_implicit_render.rb:6:in `block in send_action'
actionpack (6.1.3.2) lib/action_controller/metal/basic_implicit_render.rb:6:in `tap'
actionpack (6.1.3.2) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
Yet that template clearly exists in the proper path (its corresponding partial is also present in the directory) as shown here:
This is perplexing as the warning message is contrary to the reality. The only assumptions that come to mind are that of some handling of form_with cmobined with the scope or the question of variant
What is mistaken here?
I am currently working on the Ruby on Rails tutorial by Michael Hartl. I am trying to add a page for each user in my database by creating an HTML with embedded ruby page in the views directory. The code for show.html.erb is below:
<%= #user.name %>, <%= #user.email %>
When I add the user to the user_controller.rb file, it looks like this:
class UsersController < ApplicationController
def show
#user = User.find(params[:id])
end
def new
end
end
When I run the rails server and click on open up the users/1 URL, I get a NameError complaining about an uninitialized constant. The error and trace is below:
NameError in UsersController#show
uninitialized constant UsersController::User
Rails.root: /usr/sample_app
Application Trace | Framework Trace | Full Trace
app/controllers/users_controller.rb:3:in `show'
actionpack (3.2.12) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.12) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.12) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.12) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.12) lib/active_support/callbacks.rb:414:in
.
.
.
.
Please let me know how to go about this because I cannot pass my spec tests with this error. If anyone has any suggestions or insight I would greatly appreciate them.Thank you.
Controller file name should be users_controller.rb
As you mentioned in comment you don't have any User model defined. To create model run rails g model user name:string email:string. This will create User model with attributes name and email.
Try Rails scaffolding and see what files it creates(in controller, model and views ignore other files for now) and see the contents of those files. To use scaffold for creating User is as below:
rails g scaffold user name:string email:string
rake db:migrate
Calling "sanitize" method on anything causes a missing method error in Rails 3 with Collective Idea's Money Gem
sanitize "trololo"
=>
undefined method `id2name' for {:instance_writer=>false}:Hash
collectiveidea-money (1.7.4) lib/support/cattr_accessor.rb:7:in `block in cattr_reader'
collectiveidea-money (1.7.4) lib/support/cattr_accessor.rb:5:in `each'
collectiveidea-money (1.7.4) lib/support/cattr_accessor.rb:5:in `cattr_reader'
collectiveidea-money (1.7.4) lib/support/cattr_accessor.rb:54:in `cattr_accessor'
actionpack (3.2.8) lib/action_controller/vendor/html-scanner/html/sanitizer.rb:48:in `<class:LinkSanitizer>'
actionpack (3.2.8) lib/action_controller/vendor/html-scanner/html/sanitizer.rb:47:in `<module:HTML>'
actionpack (3.2.8) lib/action_controller/vendor/html-scanner/html/sanitizer.rb:5:in `<top (required)>'
actionpack (3.2.8) lib/action_view/helpers/sanitize_helper.rb:174:in `white_list_sanitizer'
actionpack (3.2.8) lib/action_view/helpers/sanitize_helper.rb:60:in `sanitize'
Has anyone experienced this error before?
After digging around in the source code I found this: The money gem defines the cattr_accessor helper methods (see in file YOUR_GEM_DIR/collectiveidea-money-1.7.4/lib/support/cattr_accessor.rb) as does active_support (see in file YOUR_GEM_DIR/activesupport-3.2.8/lib/active_support/core_ext/class/attribute_accessors.rb).
Unfortunately, the implementation in the money gem differs from the one in active_support. And in your case, the money gem has been loaded after active_support and overwrote the *good* active_support implementation.
You can "fix" it by making sure that the money gem is loaded before active_support. If you post more details about your application, I can tell you how to do that...
However, the money gem seems to be pretty outdated, so I suggest you replace it with something that is more recent and actively maintained...
After upgrade to Rails 3.0.10 I'm getting strange error if I set config.cache_classes=true
NoMethodError (undefined method increment_counter' for ActiveRecord::Relation:Class):
activerecord (3.0.10) lib/active_record/associations.rb:1553:inbelongs_to_counter_cache_after_create_for_form'
activesupport (3.0.10) lib/active_support/callbacks.rb:424:in _run_create_callbacks'
activerecord (3.0.10) lib/active_record/callbacks.rb:277:increate'
activerecord (3.0.10) lib/active_record/persistence.rb:257:in create_or_update'
activerecord (3.0.10) lib/active_record/callbacks.rb:273:increate_or_update'
activesupport (3.0.10) lib/active_support/callbacks.rb:444:in _run_save_callbacks'
activerecord (3.0.10) lib/active_record/callbacks.rb:273:increate_or_update'
activerecord (3.0.10) lib/active_record/persistence.rb:60:in save!'
activerecord (3.0.10) lib/active_record/validations.rb:49:insave!'
activerecord (3.0.10) lib/active_record/attribute_methods/dirty.rb:30:in `save!'
...
I'm saving Answer model which has belongs_to relation with counter cache:
belongs_to :form, :counter_cache => true
Strangest thing is that after server restart first save works fine and after that I start getting such exceptions.
Maybe someone could advise where I could start digging for a cause?
The problem was caused by outdated acts_as_taggable_on_steroids gem which was causing class cache issues with Rails3. Switched to acts-as-taggable-on gem - problem solved.
I keep getting the following error when sending a simple e-mail via ActionMailer in Rails:
NoMethodError: undefined method `encode!' for "Hello":String
This is triggered whenever the following is run:
def hello_world_email()
mail( :from => "me",
:to => "you,
:subject => "Hello World"
)
end
From researching this, it looks like it's caused by the differences between Ruby 1.8.7 and 1.9.*, which has built-in character encoding support.
Is there any way of getting ActionMailer to work with Ruby 1.8.7 and avoid this issue? (I can upgrade Ruby on my machine, but I can't do the same for everyone else working on the project). Given that the whole of Rails 3.0.9 (of which ActionMailer is a part) is meant to work with Ruby 1.8.7, I keep thinking that there must be a way...
Note: My exact version of Ruby is ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] (pre-installed on OSX).
You may have an issue with using Ruby 1.8 and having a constant Encoding defined by a gem.
For example we found an issue with a class that was including REXML at a global scope.
The line in question in the library was:
value.encode!(charset) if defined?(Encoding) && charset
This is checking for a global constant called Encoding. (Which could be defined in any gem at global scope.) Our problem was actually the include which then made REXML::Encoding available everywhere as Encoding. You could try grepping or acking your codebase for "module Encoding" or "class Encoding".
Hope this helps.
The stack trace below defines the problem.
NoMethodError: undefined method `encode!' for "Generate":String
mail (2.2.19) lib/mail/fields/unstructured_field.rb:169:in `encode'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:138:in `fold'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:108:in `wrapped_value'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:70:in `do_encode'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:52:in `encoded'
mail (2.2.19) lib/mail/field.rb:123:in `send'
mail (2.2.19) lib/mail/field.rb:123:in `method_missing'
mail (2.2.19) lib/mail/header.rb:190:in `encoded'
mail (2.2.19) lib/mail/header.rb:189:in `each'
mail (2.2.19) lib/mail/header.rb:189:in `encoded'
mail (2.2.19) lib/mail/message.rb:1708:in `encoded'
actionmailer (3.0.10) lib/action_mailer/base.rb:445:in `set_payload_for_mail'
actionmailer (3.0.10) lib/action_mailer/base.rb:425:in `deliver_mail'
activesupport (3.0.10) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.10) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.10) lib/active_support/notifications.rb:52:in `instrument'
actionmailer (3.0.10) lib/action_mailer/base.rb:424:in `deliver_mail'
mail (2.2.19) lib/mail/message.rb:230:in `deliver'
I had the same error, when trying to test my devise confirmation emails. Weird thing was, running the test isolated did not throw this exception. Running the whole stack did. After doing a binary search, i found, that one of my specs used REXML to parse some content.
require 'spec_helper'
require 'rexml/document'
include REXML
doc = Document.new(response.body)
I dont't know, why i included REXML, presumably, because i wanted to save the REXML:: in front of Document. But changing the code to this fixed the problem:
require 'spec_helper'
require 'rexml/document'
doc = REXML::Document.new(response.body)
if you happen to use code like this somewhere, this may fix this encode! issue with ruby 1.8.7
I found the issue to be with the mailer gem, changing to 2.2.13 fixed it for me.