小编Man*_*der的帖子

模型(#...)预期,使用select标签时出现String(#...)错误

我搭建了一个简单的例子来说明我遇到的问题.在这个例子中,我有一个Starship和一个Pilot.我希望能够在创建时将现有的飞行员分配给星舰.

starship.rb

class Starship < ApplicationRecord
  has_one :pilot

  validates :name, presence: true
end
Run Code Online (Sandbox Code Playgroud)

pilot.rb

class Pilot < ApplicationRecord
  belongs_to :starship, optional: true

  validates :name, presence: true
end
Run Code Online (Sandbox Code Playgroud)

飞船/ _form.html.erb

<div class="field">
  <%= f.label :pilot %>
  <%= f.select :pilot, Pilot.all %>
</div>
Run Code Online (Sandbox Code Playgroud)

starships_controller.rb

  def starship_params
    params.require(:starship).permit(:name, :pilot)
  end
Run Code Online (Sandbox Code Playgroud)

参数哈希

{"name"=>"Nostromo", "pilot"=>"#<Pilot:0x007f85ff547f90>"}
Run Code Online (Sandbox Code Playgroud)

我得到了这个错误

Pilot(#70106745549840) expected, got String(#70106709663840)
Run Code Online (Sandbox Code Playgroud)

我看到我的飞行员在哈希中作为字符串发送,但我似乎没有找到我应该怎么做的否则.

ruby ruby-on-rails has-one ruby-on-rails-5

2
推荐指数
1
解决办法
1284
查看次数

Rails设计中出现Gmail错误

我目前正在使用带有邮件系统的应用程序。它工作正常,发送了一封欢迎电子邮件并发送了重置密码的说明,但是现在并且只有当我尝试发送重置说明时,我才出现此错误。

ArgumentError (SMTP From address may not be blank: nil):
Run Code Online (Sandbox Code Playgroud)

我正在使用这样的自定义域noreply@mycustomdomain.com ,这是我的配置

development.rb

 config.action_mailer.raise_delivery_errors = true
 config.action_mailer.perform_caching = false
 config.action_mailer.default_url_options = { host: 'localhost:3000' }

 config.action_mailer.delivery_method = :smtp
 config.action_mailer.smtp_settings = {
     address: 'smtp.gmail.com',
     port: '587',
     domain: 'gmail.com',
     authentication: :plain,
     enable_starttls_auto: true,
     user_name: Rails.application.secrets.mailer_username,
     password: Rails.application.secrets.mailer_password
}
Run Code Online (Sandbox Code Playgroud)

任何的想法 ?

编辑

class UserMailer < ApplicationMailer
  default from: 'noreply@mycustomdomain.com'

  def welcome_email(user)
    @user = user
    @url = 'http://localhost:3000/users/sign_in'
    mail(to: @user.email, subject: 'Bienvenue')
  end

  def generate_new_password_email
    user = User.find(params[:user_id])
    user.send_reset_password_instructions
  end

  def reset_password; end …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails actionmailer devise

2
推荐指数
2
解决办法
3194
查看次数

Angular 4 typescript从promise中获取数组

我收到了从返回的承诺中存储数据的麻烦.

为了确保确实返回了我想要的值,我将其记录下来.

private fetchData() {
    this._movieFranchiseService.getHighestGrossingFilmFranchises()
      .then((franchises: FilmFranchise[]) => {
        console.log(franchises)
    });
}
Run Code Online (Sandbox Code Playgroud)

但现在我想存储它.

private franchises: FilmFranchise[] = [];

private fetchData() {
    this._movieFranchiseService.getHighestGrossingFilmFranchises()
      .then((franchises: FilmFranchise[]) => this.franchises = franchises);
    console.log(this.franchises);
}
Run Code Online (Sandbox Code Playgroud)

我得到的所有代码都是一个空数组.那么为什么没有this.franchises正确分配?

附加模型,模拟和服务

export class FilmFranchise {
  id: number;
  name: string;
  revenue: number; // Revenue in billion U.S dollars
}

export var FRANCHISES: FilmFranchise[] = [
    { id: 1, name: 'Marvel Cinematic Universe', revenue: 13.47 },
    { id: 2, name: 'J.K Rowling\'s Wizarding World', revenue: 8.54 },
    { …
Run Code Online (Sandbox Code Playgroud)

promise typescript angular

2
推荐指数
1
解决办法
1119
查看次数