Forum: Ruby on Rails Problem with new action

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7e810c122918c5afe00f3b4f963b6968?d=identicon&s=25 JHuizingh (Guest)
on 2008-10-15 04:55
(Received via mailing list)
I'm having issues submitting a form to the create action.

In routes I have

map.resources :encryption_passphrases


This resource is not using an ActiveRecord model, so I can't use the
form_for method in the view.


In app/views/encryption_passphrases/new.html.erb I have this:

<% form_tag(encryption_passphrases_url, :method => "post") do |f| %>
  <p>
    <%= password_field_tag :encryption_passphrase %>
  </p>
  <p>
    <%= submit_tag "Create" %>
  </p>
<% end %>

This results in the following html:

<form action="http://localhost:3000/encryption_passphrases"
method="post"><div style="margin:0;padding:0"><input
name="authenticity_token" type="hidden"
value="a938464567fec5b2c2d90421275beb83776a2ae7" /></div>

  <p>
    <input id="encryption_passphrase" name="encryption_passphrase"
type="password" />
  </p>

  <p>
    <input name="commit" type="submit" value="Create" />
  </p>
</form>



When I hit the Create button, I get this error on the resulting page:

"Unknown action
No action responded to index"

I don't know why it's going to the get http method because it says
post in the form tag.

Can anybody tell me how to fix this?

Thanks,

Jonathan
5ca17be18ed84b27dc0d9062216e2da8?d=identicon&s=25 Christian Johansen (chrisjoha)
on 2008-10-15 17:34
Try running "rake routes" to see if the URL you get is recognized as a
resource url. Maybe the :controller/:action/:id route outranks your
resources route. The resources route should be specified higher up in
the file.
7e810c122918c5afe00f3b4f963b6968?d=identicon&s=25 JHuizingh (Guest)
on 2008-10-16 00:46
(Received via mailing list)
Christina,

Thanks for the response.

This is what my rake routes command outputs.  The
encryption_passphrases resource is at the top of everything in the
application.  The :controller/:action/:id route is at the very bottom.


              encryption_passphrases GET    /
encryption_passphrases
{:controller=>"encryption_passphrases", :action=>"index"}
    formatted_encryption_passphrases GET    /
encryption_passphrases.:format
{:controller=>"encryption_passphrases", :action=>"index"}
                                     POST   /
encryption_passphrases
{:controller=>"encryption_passphrases", :action=>"create"}
                                     POST   /
encryption_passphrases.:format
{:controller=>"encryption_passphrases", :action=>"create"}
           new_encryption_passphrase GET    /encryption_passphrases/
new
{:controller=>"encryption_passphrases", :action=>"new"}
 formatted_new_encryption_passphrase GET    /encryption_passphrases/
new.:format
{:controller=>"encryption_passphrases", :action=>"new"}
          edit_encryption_passphrase GET    /
encryption_passphrases/:id/edit
{:controller=>"encryption_passphrases", :action=>"edit"}
formatted_edit_encryption_passphrase GET    /
encryption_passphrases/:id/edit.:format
{:controller=>"encryption_passphrases", :action=>"edit"}
               encryption_passphrase GET    /
encryption_passphrases/:id
{:controller=>"encryption_passphrases", :action=>"show"}
     formatted_encryption_passphrase GET    /
encryption_passphrases/:id.:format
{:controller=>"encryption_passphrases", :action=>"show"}
                                     PUT    /
encryption_passphrases/:id
{:controller=>"encryption_passphrases", :action=>"update"}
                                     PUT    /
encryption_passphrases/:id.:format
{:controller=>"encryption_passphrases", :action=>"update"}
                                     DELETE /
encryption_passphrases/:id
{:controller=>"encryption_passphrases", :action=>"destroy"}
                                     DELETE /
encryption_passphrases/:id.:format
{:controller=>"encryption_passphrases", :action=>"destroy"}
.
.
. {other controllers}
.
                                            /:controller/:action/:id
                                            /:controller/:action/:id.:format



I've worked around the issue by causing the index action to call the
create method, but I'd rather have it work as designed...

Any other suggestions?

Thanks,
Jonathan
This topic is locked and can not be replied to.