Ruby on Rails
Thursday, April 30, 2015
First thing is I'm no using form_for or any other form tags.
-- I have a Model
class Modelname < ActiveRecord::Base
def self.methodfirst #Class method
:
# Some code
:
end
def methodsecond #Instance method
:
# Some code
:
end
end
a controller
class SomenamesController < ApplicationController
def new
@variable = Modelname.new
end
def create
Modelname.methodfirst # calling class method methodfirst redirect_to(new_somename_path)
end
def deduction
Modelname.new.methodsecond # calling instance method methodsecond
end
end
a partial file _form.html.erb rendered from new.html.erb
<div class="row">
<div class="actions">
<%= button_to "create action", somenames_path, :class => "btn btn-primary" %>
</div>
<div class="actions">
<%= button_to "deduction", action: "deduction", :class => "btn btn-primary", method: "post" %>
</div>
</div>
new.html.erb
<%= render 'form' %>
Problem is: First button is working fine but not the second
<%= 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"
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4e9adfea-7fb7-4b0b-bb8c-e0f6fbcb7689%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment