Methode for layout search bar?

Is it possible to define a methode for a search bar in my layout which
will search for an article for exemple and then show the article
redirecting to the edit view ?

Thanks for your help!

On 16 May 2014 10:38, Fab F. [email protected] wrote:

Is it possible to define a methode for a search bar in my layout which
will search for an article for exemple and then show the article
redirecting to the edit view ?

Yes. Work right through a good tutorial such as railstutorial.org
(which is free to use online) and then you should at least know how to
start. Then if necessary come back and ask specific questions about
the particular bits you have problems with.

Colin

My specific question is where can I define the methode for the layout
because he hasn’t a controller?

On 16 May 2014 11:27, Fab F. [email protected] wrote:

My specific question is where can I define the methode for the layout
because he hasn’t a controller?

Please quote the previous message in your reply so that it easier to
follow the thread. Note that this is a mailing list not a forum
(though you may be accessing via a forum-like interface).

If the search actions do not fit well with one of the existing
controller then just create one specifically for searches. However,
if the search is specifically for Articles then generally you would
put search actions in the articles controller.

Colin

Please quote the previous message in your reply so that it easier to
follow the thread. Note that this is a mailing list not a forum
(though you may be accessing via a forum-like interface).

Sorry I will pay attention new time!

If the search actions do not fit well with one of the existing
controller then just create one specifically for searches. However,
if the search is specifically for Articles then generally you would
put search actions in the articles controller.

Colin

My search bar will appear on all my views so I think it will be better
if I create a new controller but how I must call it if my view is in
views/pages/currentop? And how my view will be associated to this
controller?

Fab

On 16 May 2014 14:54, Walter Lee D. [email protected] wrote:

controller then just create one specifically for searches. However,
That is down to how you structure your form tag in that view. This can be as
simple as a hand-coded form (no need for form_for helper here) and whatever you
called your controller (or however you defined your search route) will determine
what the actual path is. Something like this:

    <form action="/search/results" method="get">
            <input type="search" name="q">
    </form>

Now if you have a search_controller.rb with a results method, and you made a
route to hook that up, you should be in business.

In addition to Walter’s suggestion, I think, Fab, you are a little
confused about the way that views and controllers work. The form that
Walter suggests is shown in the layout and does not need to come from
any particular controller. It is the action that is invoked when the
user requests the search that goes to a controller. So you could just
as easily put the search action in the articles controller just by
changing the form action to articles/search and providing the
appropriate route to a search action.

Colin

On May 16, 2014, at 9:42 AM, Fab F. wrote:

Colin

My search bar will appear on all my views so I think it will be better
if I create a new controller but how I must call it if my view is in
views/pages/currentop? And how my view will be associated to this
controller?

That is down to how you structure your form tag in that view. This can
be as simple as a hand-coded form (no need for form_for helper here) and
whatever you called your controller (or however you defined your search
route) will determine what the actual path is. Something like this:

Now if you have a search_controller.rb with a results method, and you
made a route to hook that up, you should be in business.

Walter

Finaly I find this tutorial to solve my problem:

http://www.stefanosioannou.com/rails-4-simple-search-form/

On 16 May 2014 14:54, Walter Lee D. [email protected] wrote:

controller then just create one specifically for searches. However,
That is down to how you structure your form tag in that view. This can be as
simple as a hand-coded form (no need for form_for helper here) and
whatever you
called your controller (or however you defined your search route) will
determine
what the actual path is. Something like this:

    <form action="/search/results" method="get">
            <input type="search" name="q">
    </form>

Now if you have a search_controller.rb with a results method, and you made a
route to hook that up, you should be in business.

Thanks for your answer Walter about the use of ‘action’ form’s option,
now I know how to make a new methode I just have to watch how to display
only only one element in my view.

In addition to Walter’s suggestion, I think, Fab, you are a little
confused about the way that views and controllers work. The form that
Walter suggests is shown in the layout and does not need to come from
any particular controller. It is the action that is invoked when the
user requests the search that goes to a controller. So you could just
as easily put the search action in the articles controller just by
changing the form action to articles/search and providing the
appropriate route to a search action.

Colin

Thanks for your anwser too Colin! I think I wasn’t confused about the
way that views and controllers work but it’s just that I did’nt know we
can use ‘action:/path’ to set the controller’s path.