开发者

Rails, Posting to a Custom Method

in my group controller I have two开发者_开发百科 methods:

  def new
    @group = Group.new

    respond_to do |format|
      format.js
    end
  end

  def new_beta
    @group = Group.new

    respond_to do |format|
      format.js
    end
  end

I have a form that starts like so:

 <%= form_for Group.new, :remote => true do |f| %>

How can I get the form_for to post to the new_beta controller? Thanks


You can set :

 <%= form_for Group.new, :url=>{ :action =>"new_beta", :controller =>
"group"}, :remote => true do |f| %>

(you can also -preferably- directly use a named route instead of ":url => ")


First this is bad practice but..

in your routes add

resources :groups do
  member do
    get :new_beta
    post :new_beta_create
  end
end

Now

 <%= form_for Group.new, :url => new_beta_create_groups_path, :remote => true do |f| %>

However I recommend creating a new controller called something like: alternate_groups_controller. Even better make a namespace for them.

Good luck

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜