在Home#new中与shopify -NoMethodError在Rails中与无表模型作斗争

时间:2018-11-18 22:22:00

标签: ruby-on-rails model-view-controller model nomethoderror undefined-function

我正在为shopify创建一个简单的应用程序,用户在该应用程序中输入用户的电子邮件地址,然后使用此电子邮件通过API将shopify商店订单历史记录发送到该地址。

由于无需存储电子邮件,因此我创建了一个无表模型,作为Railscast第193、219条中的教程,但出现此错误

“ Home#new中的NoMethodError” 未定义的方法“ emails_path”,用于#<#:0x00005574bfa8a258> 你的意思是? image_path

而且我不知道如何解决它,因为我仍然对RoR还是很熟悉,所以我也会为该错误添加一个屏幕截图,这是我的文件

home_controller.rb

class HomeController < ShopifyApp::AuthenticatedController
  # solve the  invalid authenticaty token problem by adding this security 
  # protect_from_forgery is included by default in application controller but we have to
  # add it here manually
  protect_from_forgery

  def index
    @products = ShopifyAPI::Product.find(:all, params: { limit: 10 })
    @orders = ShopifyAPI::Order.find(:all, params: { limit: 10 })
    @webhooks = ShopifyAPI::Webhook.find(:all)
  end

  def new
    @email = Email.new
  end

  def create
    @email = Email.new(params[:themail])
    #byebug
    if @email.valid?
        redirect_to '/ordertocsv'
    else
        redirect_to root_url
    end
  end

end

models / email.rb

class Email
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming

  attr_accessor :themail

  validates_presence_of :themail
  validates_length_of :themail, :maximum => 500

  def persisted?
    false
  end

end

views / home / new.html.erb

<% form_for @email do |f| %>
  <%= f.error_messages %>
  <p>
    <%= f.label :themail %><br />
    <%= f.email_field :themail, required: true %>
  </p>
  <p>
    <%= f.submit "Send Email" %>
  </p>
<% end %>

routes.rb

Rails.application.routes.draw do
  root to: 'home#index'
  get "/ordertocsv", to: "home#new"
  post "/ordertocsv", to: "home#create"
  mount ShopifyApp::Engine, at: '/'
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

错误屏幕截图 enter image description here

0 个答案:

没有答案