I'm trying to redirect to the index action of another controller once I have accomplished a create in the current controller. But the redirect fails, resulting in a url pointing to the index action in the current controller (which doesn't exist, resulting in a blank page)
Here is my code :
clients_controller.rb
def create
@client = Client.new(params[:client])
respond_to do |format|
if @client.save
session[:client_id] = @client.id
redirect_to produits_url
else
format.html { render action: "new" }
end
end
end
produits_controller.rb
def index
@produits = current_client.produits
respond_to do |format|
format.html # index.html.erb
format.json { render json: @produits }
end
end
routes.rb
get "home/index"
get "log_out" => "sessions#destroy", :as => "log_out"
get "log_in" => "sessions#new", :as => "log_in"
get "inscription" => "clients#new", :as => "inscription"
match '/a_propos', to: 'application#a_propos'
resources :sessions
namespace "admin" do
resources :clients, only: [:index]
end
resources :clients, only: [:create, :edit, :update, :destroy]
resources :produits
rake routes
home_index GET /home/index(.:format) home#index
log_out GET /log_out(.:format) sessions#destroy
log_in GET /log_in(.:format) sessions#new
inscription GET /inscription(.:format) clients#new
a_propos /a_propos(.:format) application#a_propos
sessions GET /sessions(.:format) sessions#index
POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
edit_session GET /sessions/:id/edit(.:format) sessions#edit
session GET /sessions/:id(.:format) sessions#show
PUT /sessions/:id(.:format) sessions#update
DELETE /sessions/:id(.:format) sessions#destroy
admin_clients GET /admin/clients(.:format) admin/clients#index
clients POST /clients(.:format) clients#create
edit_client GET /clients/:id/edit(.:format) clients#edit
client PUT /clients/:id(.:format) clients#update
DELETE /clients/:id(.:format) clients#destroy
produits GET /produits(.:format) produits#index
POST /produits(.:format) produits#create
new_produit GET /produits/new(.:format) produits#new
edit_produit GET /produits/:id/edit(.:format) produits#edit
produit GET /produits/:id(.:format) produits#show
PUT /produits/:id(.:format) produits#update
DELETE /produits/:id(.:format) produits#destroy
root / home#index