0

Rails 4.1, reaching the driver knowing edit and use _form.html.erb again. I tried to do the following:

 

<% = Form_for @user, :controller => "admin/users" do | f |%>


<button type='submit'>Guardar</button>

<% end %>

#Controller ===============

def new
    @user = User.new
  end




def create
    @user = User.new(user_params)
    respond_to do |format|
      if @user.save
          format.html { redirect_to admin_users_url, notice: "User #@user.name} was successfully created." }
          format.json { render :controller => 'admin/users', action: 'show', status: :created, location: @user }
      else
          format.html { render :controller => 'admin/users', action: 'new' }
          format.json { render json: @user.errors, status: :unprocessable_entity }
      end 
    end   
  end

But it does not work I can not get to the route that is my controller ("admin / users"), if anyone can help me

1 Answers1

0

I assume that you have your admin routes defined in your config/routes.rb like this:

# in config/routes.rb
namespace :admin do
  resources :users
end

See: Rails Guide about namespaces in routes

Then this should work for an admin namespaced form in your view:

<%= form_for [:admin, @user] do |f| %>
  ...
<% end %>

See: Rails Guide about namespaces and form helper

Your controller code looks okay, but please ensure that the controller is namespaced too:

# in app/controllers/admin/users_controller.rb
module Admin
  class UsersController
    # ...
  end
end
spickermann
  • 100,941
  • 9
  • 101
  • 131