Instead of it going to the index, it seems to be going to the create action instead.
The only way I managed to get around it was by doing <%= form_tag(dogs_path, method: :get) %> but that resulted in the URL containing the utf-8 and commit params it it.
After doing a little more digging, It seems I was half way there changing the method to GET after watching this RailsCast, the way I stop the commit=search from appearing is by doing name: nil on the submit_tag helper method.
Iwantadog::Application.routes.draw do
root to: "homes#show", via: :get
get "signup", to: "users#new", as: "signup"
get "login", to: "sessions#new", as: "login"
delete "logout", to: "sessions#destroy", as: "logout"
resources :users, only: [:new, :create]
resource :session, only: [:new, :create, :destroy]
resource :dashboard, only: :show
resource :confirmation, only: :new
resources :dogs
end
and this is the DogsController
class DogsController < ApplicationController
before_filter :authorize, except: [:index, :show]
def index
@dogs = Dog.all
end
def new
@dog = Dog.new
end
def create
user = User.find(session['user_id'])
@dog = user.dogs.new(dog_params)
if @dog.save
redirect_to root_path
else
render "new"
end
end
def show
@dog = Dog.find(params[:id])
end
def edit
@dog = Dog.find(params[:id])
end
def update
@dog = Dog.find(params[:id])
@dog.update_attributes(dog_params)
if @dog.save
flash.notice = "Advert Successfully Updated!"
redirect_to dog_path(@dog)
else
flash.now.alert = "Advert has not been updated!"
render "edit"
end
end
def destroy
@dog = Dog.find(params[:id])
@dog.destroy
redirect_to dogs_path
end
private
def dog_params
params.require(:dog).permit(:ad_type, :title, :body, :price, :picture)
end
end