Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7979047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:39:46+00:00 2026-06-04T09:39:46+00:00

I am building a toy Rails app. I generated a scaffold for my Post

  • 0

I am building a toy Rails app. I generated a scaffold for my Post objects. Now, I want to add some search functionality to the scaffold generated view. I am following http://railscasts.com/episodes/37-simple-search-form to add the search functionality.

To app/views/posts/index.html.erb I add

<% form_tag posts_path, :method => 'get' do %>
  <p>
     <%= text_field_tag :search, params[:search]   %>
     <%= submit_tag "Search", :name => nil %>
  </p>
<% end %>

and then the code for listings follow.

In controllers/posts_controller.rb I have

class PostsController < ApplicationController
  # GET /posts
  # GET /posts.json
  def index
    @posts = Post.search(params[:search])
    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @posts }
    end
  end

In model/post.rb I have

class Post < ActiveRecord::Base
  attr_accessible :description, :image_url, :title
        validates :name, :presence => true
        validates :title, :presence => true,
                        :length => { :minimum => 5 }
  def self.search(search)
        if search
                find(:all, :conditions => ['name LIKE?', "%#{$search}%"])
        else
                find(:all)
        end
  end
end

When I run the server, I don’t get any errors, but the form doesn’t show up. I looked at the generated page source, and there is no form there. What is going on? Is there a way to debug situations like these?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:39:48+00:00Added an answer on June 4, 2026 at 9:39 am

    Since Rails 3 the form_tag helper itself return the html it produces. The equal sign is needed. So please change the first line to

    <%= form_tag posts_path, :method => 'get' do %>
    

    That was different in Rails 2. As the railscasts episode is quite old you may run into other issues as well.

    See the Rails API as well.

    Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Building a search with some custom objects and three scopes: All , Active ,
I am building a toy app using core data for two entities Log (attributes
I'm building a little synth app/music toy which uses soundFonts. I have a varying
Building an MVC 3 app with Razor and I have some information persisted in
Building a Silverlight 5 app that runs in the browser but getting some nagging
Building a django app with some mostly static pages at the front of the
I'm currently building a toy assembler in c# (going through The Elements Of Computing
I'm building a toy compiler as a learning project, and I'm hovering around the
Building a Django app on a VPS. I am not very experienced with setting
Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.