Ruby on Rails Sunday, October 31, 2010

Thanks for that, but I am still getting a syntax error. Now:-
SQLite3::SQLException: near "%": syntax error: SELECT
"homepages".* FROM "homepages" WHERE (section = %'Gar'%)

This shows that the correct text is being passed, but the syntax is
still incorrect.
Don

On Oct 31, 3:20 am, Sampath Munasinghe <sampathni...@gmail.com> wrote:
> self.where('section = %?%', search_item)
>
> On Sun, Oct 31, 2010 at 7:39 AM, MDM <don.m...@gmail.com> wrote:
> > I am trying to do a search where I can enter a part of a word and the
> > search find all occurrences of that part word in the field. The above
> > subject does not work. Can anyone help
> > I am using Rails 3 and ruby 1.9.2
> > I use to be able to do it in rails 2.x.
> > In my Model I have the following:-
> >  def self.search(search_item)
> >    if search_item
> >     self.where('section = ?', '%:search_item%')
> >    else
> >      self.all
> >    end
> >  end
>
> > In my controller I have:-
> >    @homepages = Homepage.search(params[:search])
> >    respond_to do |format|
> >      format.html # index.html.erb
> >      format.xml  { render :xml => @homepages }
> >      format.js {render :js => @homepages}
> >    end
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Ruby on Rails: Talk" group.
> > To post to this group, send email to rubyonrails-talk@googlegroups.com.
> > To unsubscribe from this group, send email to
> > rubyonrails-talk+unsubscribe@googlegroups.com<rubyonrails-talk%2Bunsubscribe@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment