2010-10-30 32 views
11

Quando viene elaborata una richiesta POST, params [: id] restituisce il valore di "id" memorizzato nel modulo che è stato pubblicato.Come ottenere i parametri URL in Rails?

Tuttavia, desidero ottenere il valore memorizzato nell'URL (stringa di query).

def some_action 
    id = params[:id] # Gets id from here: /some_action?id=[VALUE] only when request.post? is false 
    if request.post? 
    # Do some stuff, can't get the id value from the url 
    ... 
end 

Così come ottenere il valore dal URL in una richiesta POST?

risposta

11

è lo stesso dei parametri GET. Per dimostrare che, ho un modulo di ricerca che i posti un parametro per la stessa azione:

def invite 

    if request.post? 

     search= [params[:search]] 
     #... 

    end 
end 

E nella vista - forse il problema viene da questo

<% form_tag do %> 
     <%= text_field_tag :search, params[:search] %> 
     <%= submit_tag "Rechercher" %> 
<% end %> 
Problemi correlati