1

I am trying to create a multi button form. The if I press "create checked" it does create copyies is it is should do. I have created the routes.

My controller:

  def create_multiple
    @webhost = Webhost.find(params[:webhost_ids])
    if params[:delete_button]
     render 'admin/webhosts/delete_multiple'
    else
    @webhost.each do |webhost|
    Webhost.create(webhost.attributes)
    end
    end
    respond_to do |format|
      format.html { redirect_to(:admin_webhosts, :notice => 'Konkurrancerne er nu slettet') }
      format.xml  { head :ok }
    end
end

def delete_multiple
    @webhost = Webhost.find(params[:webhost_ids])
    @webhost.each do |webhost|
    webhost.destroy
    end
    respond_to do |format|
      format.html { redirect_to(:admin_webhosts, :notice => 'Konkurrancerne er nu slettet') }
      format.xml  { head :ok }
    end
end  

In my view I have:

<%= submit_tag "Create Checked" %>  
<%= submit_tag "Delete Checked", :name => 'delete_button' %>  

When I press the delete checked button I get this error: Template is missing

Missing template admin/webhosts/delete_multiple with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "C:/Rails/webhostapp/app/views", "C:/Ruby192/lib/ruby/gems/1.9.1/gems/devise-1.1.5/app/views", "C:/Ruby192/lib/ruby/gems/1.9.1/gems/kaminari-0.10.4/app/views", "C:/Rails/webhostapp", "C:/"

And the URL is: http://localhost:3000/admin/webhosts/create_multiple

0

1 Answer 1

2

If I see correctly, you want to call delete_multiple when the button is clicked.

If delete_multiple is a method of your controller, you don't call it via render. render will try to look for a view called admin/webhosts/delete_multiple.html.erb or similar and show that view. See Layouts and Rendering in Rails for more on that.

What you probably want to do is just call this method as usual:

def create_multiple
    @webhost = Webhost.find(params[:webhost_ids])
    if params[:delete_button]
     delete_multiple(params) and return
    else
    # ...
end

Note that you probably need to pass the parameters to your delete_multiple method. You will have to adapt it to take the parameters as an argument of course:

def delete_multiple(params)
    @webhost = Webhost.find(params[:webhost_ids])
    @webhost.each do |webhost|
    webhost.destroy
    end
    respond_to do |format|
      format.html { redirect_to(:admin_webhosts, :notice => 'Konkurrancerne er nu slettet') }
      format.xml  { head :ok }
    end
end  
Sign up to request clarification or add additional context in comments.

3 Comments

I get a :DoubleRenderError in Admin::WebhostsController#create_multiple
I moved the end and it did fix the problem
Try again, I fixed my code now. and return assures that all subsequent calls to render from create_multiple are skipped. You shouldn't need to move anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.