ruby-on-rails - 使用命名空间编辑 simple_form_for

标签 ruby-on-rails forms namespaces simple-form

我正在尝试使用简单表单创建一个表单,以从管理界面编辑用户配置文件。

  • 这是我的路线:
  • namespace :admin do
        resources :users
        root 'admin#index'
      end
    
  • 管理员::用户 Controller :
  • def edit
         @user = User.find(params[:id])
       end
    
       def update
         @user = User.find(params[:id])
    
         if @user.update(user_params)
           redirect_to admin_user_path(@user.id)
         else
           render :edit
         end
       end
    
  • 而我的观点:
  • <div class='container mt-4'
       <%= simple_form_for [:admin, @user] do |f| %>
         <%= hidden_field_tag :authenticity_token, form_authenticity_token %>
         <%= f.input :first_name, label: 'Prénom' %>
         <%= f.input :last_name, label: 'Nom' %>
         <%= f.input :description %>
         <%= f.input :email %>
         <%= f.button :submit, 'Enregistrer les modifications', class: 'btn btn-primary rounded' %>
       <% end %>
     </div>
    

    但是我的表单不起作用,当我点击按钮时什么也没有发生......我错过了什么?

    最佳答案

    我认为问题出在路线上。

    
    namespace :admin do
        resources :users
        root 'admin#index'
        get 'admin#update'
      end
    

    关于ruby-on-rails - 使用命名空间编辑 simple_form_for,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54714053/

    相关文章:

    ruby-on-rails - Nokogiri 解析完全在本地主机上工作,但部分在 heroku 上工作

    php - 表单 $Post 中的数据库输入无法正常工作

    c# - 使用类名获取用于我们项目的引用 dll 名称

    python - 函数创建的类的虚拟名称在函数返回后似乎仍然存在-python

    ruby-on-rails - 代码更改后,Rails 开发服务器需要很长时间才能重新加载

    ruby-on-rails - 具有动态嵌套数量的模型的 Rails 表单 :has_many

    javascript - 在Rails中使用Ajax将div替换为partial

    django 在干净的方法中更改表单数据

    html - 删除标签文本而不删除标签内的文本框

    java - xml命名空间到java,如何建模 'choice'?