Rails form_tag going to create action instead of index

I am putting a search field on my homepage using the form_tag helper method.

However when I do the following code

<%= form_tag(dogs_path) %>
  <%= text_field_tag "search" %>
  <%= submit_tag "Search" %>
<% end %>

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.

I just want it so when you press search it takes you to the url www.example.com/dogs?search=test

Any help or advice would be appreciated.


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.

How do I stop the utf-8 parameter showing up?

Hi @scott,

Can you post your routes.rb and the DogsController?

Hi @geoffharcourt

This is the routes.rb file.

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

and this is the DogsController

class DogsController < ApplicationController
  before_filter :authorize, except: [:index, :show]
  def index
    @dogs = Dog.all

  def new
    @dog = Dog.new

  def create
    user = User.find(session['user_id'])
    @dog = user.dogs.new(dog_params)
    if @dog.save
      redirect_to root_path
      render "new"

  def show
    @dog = Dog.find(params[:id])

  def edit
    @dog = Dog.find(params[:id])

  def update
    @dog = Dog.find(params[:id])
    if @dog.save
      flash.notice = "Advert Successfully Updated!"
      redirect_to dog_path(@dog)
      flash.now.alert = "Advert has not been updated!"
      render "edit"

  def destroy
    @dog = Dog.find(params[:id])
    redirect_to dogs_path


  def dog_params
    params.require(:dog).permit(:ad_type, :title, :body, :price, :picture)

Hope this helps.

@scott, even though you aren’t doing anything with the utf8 parameter, Rails is. It’s to correct some issues in IE’s parameter encoding. You can find more information here What is the _snowman param in Ruby on Rails 3 forms for? - Stack Overflow

If you really want to remove it, the solution is not not use the form_tag helper and just write your form manually.