Two Buttons in Rails -



Two Buttons in Rails -

i'm trying 2 buttons work in rails same form. have login form both add together user , signup button. have 2 methods in controller handle these 2 different requests.

however, read suggestions using additional parameter parse determine button called. solution wouldn't need level of indirection controller method parsing? read having controller phone call controller isn't mvc practice. in case calling method within mvc controller class bad practice?

my form:

<%= form_tag("users/delegate", :method=>"post") %> <%= label_tag(:user, "username:") %> <%= text_field_tag(:user) %> <br/><br/> <%= label_tag(:password, "password:") %> <%= password_field_tag(:password) %> <br/><br/> <%= submit_tag "login", :name=>'login' %> <%= submit_tag "add user" %> <% end %>

also, how pass in arguments post request other method? did arguments not beingness passed. need pass in params other method? global variable?

def delegate if params[:login] login_post() else add_post() end end def login_post user = params[:user] password = params[:password] errcode = usermodel.login(user,password) if (errcode>0) count = errcode errcode = 1 end final_obj = {:errcode=> errcode, :count=>count} respond_to |format| format.json { render :json=>final_obj, :status=>200} end end

you should this:

def delegate if params[:login] login_post(params[:user], params[:password]) else add_post() end end def login_post(user, password) #do things end

ruby-on-rails ruby-on-rails-3

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -