经过身份验证的用户应该能够通过其信息中心的表单添加钱包地址。在我的路线
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
仪表板的Rails路线
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请求。
由于
答案 0 :(得分:0)
使用eth_address的别名
post '/eth_address', to: 'dashboard#eth_address', as: :eth_address
答案 1 :(得分:0)
解决方案是改变
form_for
on new
form_with
和新表格
<%= form_with url: :eth_address_path do |f| %>
<%= f.label :eth_address %>
<%= f.text_field :eth_address %>
<%= f.submit "Save" %>
<% end %>
效果很好