I am new to rails. Today I encountered a problem that I have no clue how to fix it.
Basically I am trying to put a input area and a submit button on one webpage, and the input values is stored in the params[:name], passing to the export_issues method defined in issues controller.
this is what the view file looks like
<%= form_tag(:controller => 'issues', :action => 'export_issues') do%>
<p>
<%= label_tag :name, "name:" %>
<%= text_field_tag :name, params[:name]%>
</p>
<%= submit_tag "Submit" %>
when i click the ‘Submit’ I got “Routing error”. But if I just press F5 refresh the error pageor type 127.0.0.1/issues/export_issues it will work just as I wanted
and this is the code related to issues controller in routes.rb
resources :issues, :only => [:index, :destroy] do
member do
post 'create_comment'
get 'mark_readed'
end
collection do
get 'export_issues'
delete 'destroy_comment'
end
end
basically what the export_issues does is to read the database and export data to a CSV file.
It worked fine without the form_tag codes taking part in.
So what is the problem ?
The reason is simple. By default
form_tagcreates form element withmethod=post. Like:will create form tag as follows:
However, our routing says, it accepts only
get. So, the form opening tag should be:For more information, please consult the apidocs.