【问题标题】:rails execute the view without execute the controller's actionrails 执行视图而不执行控制器的操作
【发布时间】:2015-10-20 17:02:40
【问题描述】:

我有一个控制器和一个动作,但rails 只显示视图而不执行动作。 我正在创建类似contact_us 的东西,所以我的路线中有

  get '/contact-us'     => 'desktop#contact_us'
  post '/contact_send'  => 'desktop#contact'

因此,在联系我们中,它向我显示表单,当我发送表单时,rails 显示contact_send 视图,但不执行控制器的操作,其中没有任何运行。

在我的控制器中

  def contact_us

  end

  def contact_send
    contact_us = Contact.new user_params
    contact_us.save

    redirect_to '/contact-us', notice: 'Contact message was send successfully.'

  end

在表单视图中,它只是一个发送到 /contact 的表单,在 taht 视图中,我只有像“这是 mi 测试视图”这样的文本来知道视图正在显示”,并且文本正在显示,但控制器动作没有运行,即使我故意写错误

【问题讨论】:

  • 我们能看到控制器方法的样子吗?也许 HTML 表单标签会有所帮助(所以我们可以看到表单操作)。您没有提供足够的数据来查明问题。

标签: ruby-on-rails debugging routes


【解决方案1】:

您的contact_send 指向desktop#contact 操作。但是您的控制器没有显示contact 操作。因此不会调用您的 contact_send 操作。

改变

post '/contact_send' => 'desktop#contact'

post '/contact_send' => 'desktop#contact_send'

并检查这是否有效。

【讨论】:

    猜你喜欢
    • 2015-11-23
    • 1970-01-01
    • 1970-01-01
    • 2014-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多