Action Controller ::MethodNotAllowed

Hi,

Iam getting the following error

ActionController::MethodNotAllowed Only get, put and delete requests are allowed.

Actually, Iam trying to have multiple actions for a form to create new record. The actions for the form are cancel, save, publish and preview.

here's the config/routes.rb file code snippet for the relevant controller - Events

map.resources :events, :member => {:manage => :get}, :new => {:preview => :post, :publilsh => :post}

The EventsController has functions for new, create, edit, update, manage, preview and publish.

the new.html.erb snippet is

<% form_for @event, :url => events_path, :html => {:multipart => true, :id => "event_form"} do |f| -%>   <%= render :partial => "form", :locals => {:f => f} %>   <%= link_to image_tag("/images/btn-cancel.png", :border => 0), dashboard_path, :style => "float:left;" %>   <%= link_to_function image_tag("/images/btn-publish.png", :border => 0), "publish_event($(this));", :style => "padding-right:20px;" %>   <%= link_to_function image_tag("/images/btn-preview.png", :border => 0), "preview_event($(this));", :style => "padding-right:20px;" %>   <input type="image" src="/images/btn-save-draft.png" name="save" value="Save" class="image_input"></input> <% end -%>

the javascript functions in application.js

function preview_event(element){   element.up('#event_form').writeAttribute('target', '_blank');   element.up('#event_form').action = "preview";   element.up('#event_form').method = "post";   element.up('#event_form').submit();   element.up('#event_form').writeAttribute('target', false); }

function publish_event(element) {   element.up('#event_form').action = "publish";   element.up('#event_form').method = "post";   element.up('#event_form').submit();     }

Iam stuck with the error. Pls help

In routes.rb (for preview & publish), use :any instead of :post, might work.

Thanks, Abhinav

Hi,

Thanks for the reply. But changing from :post to :any didn't work!!! : ( Is there some other way in which multiple actions for a form can be implemented ? Any other suggestions are welcome.

Nisha.

You can try :member or :collection depending upon your requirements. For forms, I guess you should use :member. Read rails guides for more details http://guides.rubyonrails.org/routing.html

Thanks, Abhinav

Hi,

Thanks for the prompt reply, but its not working yet!!! :frowning: Any other suggestions.

Thanks, Nisha