【问题标题】:post request in dashboard scope doesn`t work在仪表板范围内发布请求不起作用
【发布时间】:2017-10-19 07:50:36
【问题描述】:

经过身份验证的用户应该能够通过其仪表板的表单添加钱包地址。在我的路线中

scope '/dashboard', module: :dashboard do
  get '/', to: 'dashboard#index', as: '/dashboard'
  post '/eth_address', to: 'dashboard#eth_address'
end

我的表格

<%= form_for eth_address_path do |f| %>
          <%= f.label :eth_address %>
          <%= f.text_field :eth_address %>
          <%= f.submit "Save" %>
      <% end %>

在views/dashboard/dashboard/index.html.erb中

还有我的简单控制器

Dashboard::DashboardController

controllers/dashboard/dashboard_controller.rb

用方法

def eth_address
  eth_addr = params[:eth_address]
  EthereumWallet.create(user_id: current_user.id,
                      address: eth_addr)
end

仪表板的轨道路线

dashboard GET  /dashboard(.:format)  dashboard/dashboard#index
 eth_address POST /dashboard/eth_address(.:format) dashboard/dashboard#eth_address          

提交后我看到了这个:

No route matches [POST] "/dashboard"

我不知道为什么它要求我从 /dashboard 发出 POST 请求。

谢谢

【问题讨论】:

  • 显示您的路线。耙路线
  • 添加了提问的路线
  • form_for :eth_address_path

标签: ruby-on-rails ruby routing


【解决方案1】:

为 eth_address 使用别名

post '/eth_address', to: 'dashboard#eth_address', as: :eth_address

【讨论】:

  • 问题仍然存在。
【解决方案2】:

解决办法是改变

form_for

新的

form_with

和新形式

 <%= form_with url: :eth_address_path do |f| %>
          <%= f.label :eth_address %>
          <%= f.text_field :eth_address %>
          <%= f.submit "Save" %>
      <% end %>

效果不错

【讨论】:

    猜你喜欢
    • 2012-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多