【问题标题】:routes pro-blem in form ruby and railsruby 和 rails 中的路由问题
【发布时间】:2014-05-15 16:27:43
【问题描述】:

我在 ruby​​ 和 rails 中创建了一个唱歌表格

我已经创建了一个表单

<%= form_for @user, url: {action: "new"}  do |f| %>

            <%= render 'shared/error_messages' %>
            <%= f.label :name %>
            <%= f.text_field :name %>

            <%= f.label :email %>
            <%= f.text_field :email %>

            <%= f.label :password %>
            <%= f.password_field :password %>

            <%= f.label :password_confirmation, "Password Confirmation" %>
            <%= f.password_field :password_confirmation %>

            <%= f.submit "Create my account",class: "btn btn-large btn-primary" %>

        <% end %>

我已经在路线文件中写下了这个

get '/signup', to: 'users#new'

但是当我看到输出为 html 时,它看起来像这样

<form accept-charset="UTF-8" action="/users/new" class="new_user" id="new_user" method="post">

这是 post 方法,我如何在路由文件中定义 get 和 post 以及如何使用 action singup?

请帮帮我

【问题讨论】:

  • 如果没有人能够给出答案然后查询进入-1 :) 太有趣了

标签: ruby-on-rails routing routes


【解决方案1】:

在路线上这样做:

match '/signup', to: 'users#new'

【讨论】:

  • 在哪里获取和发布?
  • Match 会为您做到这一点。它会捕获 get 和 post。
  • match '/signup', to: 'users#new', via: [:get] 我已经写下来了,我的查询仍然有效
  • 当我写下它时,它会显示这个输出
    为什么不是正在行动中?
  • 在表单上试试这个 url => url_for(:action => 'signup')
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-23
  • 1970-01-01
  • 2010-11-30
  • 2011-01-31
相关资源
最近更新 更多