More than one button with custom actions inside new.html.erb

First thing is I’m no using form_for or any other form tags.

I have a controller

class SomenamesController < ApplicationController

def new
@variable = Modelname.new
end

def create
Modelname.methodfirst # methodfirst is class
method
redirect_to(new_somename_path)
end

def deduction
Modelname.new.methodsecond # calling instance method of
Modelname
end

end

a Model

class Modelname < ActiveRecord::Base
def self.methodfirst
:

Some code

:
end

def methodsecond
:

Some code

:
end
end

a partial file _form.html.erb rendered from new.html.erb

<%= button_to "create action", somenames_path, :class => "btn btn-primary" %>
<%= button_to "deduction", action: "deduction", :class => "btn btn-primary", method: "post" %>

new.html.erb
<%= render ‘form’ %>

Problem is:

<%= button_to “Start recovery printing”, recoveries_path, :class => “btn
btn-primary” %>

is working fine. Since it calls “create” action inside Somenames

But the second button is not working but throwing an error message

No route matches {:action=>“deduction”, :class=>“btn btn-primary”,
:controller=>“recoveries”, :method=>“post”}

Now how can I call custom action “deduction” written inside Somenames
controller so that it will call instance method “methodsecond”

On 30 April 2015 at 01:03, Padmahas Bn [email protected] wrote:


But the second button is not working but throwing an error message

No route matches {:action=>“deduction”, :class=>“btn btn-primary”,
:controller=>“recoveries”, :method=>“post”}

Now how can I call custom action “deduction” written inside Somenames
controller so that it will call instance method “methodsecond”

You indicated in a previous message that you had worked right through
railstutorial.org. Perhaps you missed the sections where it used
routes.rb to setup routes to control which action is called for each
request. Have a look at the rails guide on routing to see the various
options for how to do this. Also look at the other guides, they
contain a lot of useful information.

As a matter of interest, why have you posted this request for help
twice? One is quite sufficient and it is best to use plain text mode
(as you have done here).

Colin

Perhaps you missed the sections where it used
routes.rb to setup routes to control which action is called for each
reques

I haven’t missed, Since I was digging deep into model from past two
weeks,
I almost forgot there is an essential routing file between V and C among
MVC. Thank you for the hint.

As a matter of interest, why have you posted this request for help
twice? One is quite sufficient and it is best to use plain text mode
(as you have done here).

I wasn’t intend to post two messages, Since I can’t edit the post posted
in group, And when I saw my post back again I myself didn’t like the
long
question with no clue of which is the code and what is my query. So I
deleted the old one and posted the new one.

On 4 May 2015 at 15:35, Padmahas Bn [email protected] wrote:


I wasn’t intend to post two messages, Since I can’t edit the post posted in
group, And when I saw my post back again I myself didn’t like the long
question with no clue of which is the code and what is my query. So I
deleted the old one and posted the new one.

You can’t delete posts, this is a mailing list not a forum (though you
may be accessing it via a forum like interface). Once I received your
original post there is no way for you to delete it from my PC. In
such circumstances the best thing to do is just to post a follow up
message.

Cheers

Colin

You can’t delete posts, this is a mailing list not a forum (though you

may be accessing it via a forum like interface). Once I received your
original post there is no way for you to delete it from my PC. In
such circumstances the best thing to do is just to post a follow up
message.
Cheers

Pretty new for mailing list type discussion. From next time I will keep
this in mind . And sorry all for violating mailing list rules.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs