11744

How use data related to object which I'm not saving to database?

Question:

I need to use User data, which he is entering in form, but not save it.

I added attribute accessors into my User model:

attr_accessible :paypal_email, :first_name, :last_name attr_accessor :first_name attr_accessor :last_name

but how can I use it after user submits form? I need to verify account details, but didn't save them, so I need to use in controller

@user.first_name and @user.last_name

<b>My verification action:</b>

def verify @user = User.find(params[:user_id]) require 'httpclient' require 'xmlsimple' clnt = HTTPClient.new header = {"X-PAYPAL-SECURITY-USERID" => "№№№№№№№№", "X-PAYPAL-SECURITY-PASSWORD" => "333333333", "X-PAYPAL-SECURITY-SIGNATURE" => "3333333333", "X-PAYPAL-REQUEST-DATA-FORMAT" => "NV", "X-PAYPAL-RESPONSE-DATA-FORMAT" => "XML", "X-PAYPAL-APPLICATION-ID" => "APP-2J632856DC989803F" } data = {"emailAddress" => @user.paypal_email, "firstName"=> @user.first_name, "lastName" => @user.last_name, "matchCriteria" => "NAME", "requestEnvelope.errorLanguage" => "en_US"} uri = "https://svcs.paypal.com/AdaptiveAccounts/GetVerifiedStatus" res = clnt.post(uri, data, header) @xml = XmlSimple.xml_in(res.content) if res.status == 200 if @xml['accountStatus']!=nil account_status = @xml['accountStatus'][0] if account_status == "VERIFIED" redirect_to :back flash[:success] = "Your account is verified" else redirect_to :back flash[:error] = res.content end else redirect_to :back flash[:error] = res.content end else flash[:error] = "Oops! Can't conntect to PayPal" end end

and error:

Invalid request parameter: lastName</message><parameter>lastName

how I can do that ?

Answer1:

In your case, you should go for form_tag. form_tag is used to upload details that are not associated with any model object.

Answer2:

It is very simple if I understand your question correctly.

You want first_name and last_name data to be verified which is entered by Form (HTML) page.

Let us say, you have given names of respective input fields in html forms as form_first_name and form_last_name.

You can simply access them by using params[:form_first_name] and params[:form_last_name] respectively inside your controller.

Recommend

  • Outlook Com not registered
  • With one EDMX file use multiple connection strings that relate to multiple databases
  • Using Paypal Pro in Omnipay
  • JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token
  • File loader changed image file name but not the file name in HTML file
  • PHP + XML - how to rename and delete XML elements using SimpleXML or DOMDocument?
  • How to use animated gif in Firemonkey?
  • How to concat Pandas dataframe columns
  • TFS - how do I sum child task hours to parent
  • Detecting # in Scheme list
  • how to get username into sql trigger when multiple users signed on from asp membership
  • passing a default argument to a browserify module
  • HttpListener.IsSupported is false on XP SP3
  • Why must we declare a variable name when adding a method to a struct in Golang?
  • Sending cookie value via httpget but not getting the desired response
  • Enabling DTD support in Sql Server
  • GAE: Way to get reference to an HttpSession from its ID?
  • Authentication in Play! and RestEasy
  • Does Mobilefirst provide a provision to access web services directly?
  • rspec simple example getting error on request variable in integration test
  • How to attach a node.js readable stream to a Sendgrid email?
  • MongoError: Incorrect arguments
  • Django rest serializer Breaks when data exists
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • Seeking advice on Jetty HttpClient Hang
  • Spray.io: When (not) to use non-blocking route handling?
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Symfony2: How to get request parameter
  • log4net write single file for each call to log.info
  • Getting error when using KSoap library to consume .NET web services
  • embed rChart in Markdown
  • Authorize attributes not working in MVC 4
  • EntityFramework adding new object to nested object collection
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • How can I use `wmic` in a Windows PE script?
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • Conditional In-Line CSS for IE and Others?