Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9158095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:10:14+00:00 2026-06-17T13:10:14+00:00

I have a user model that includes shipping information in addition to the standard

  • 0

I have a user model that includes shipping information in addition to the standard account information.

I have three different views that can update the user’s information:

  • Wizard
  • Settings
  • Account

I know that I should be using the REST model, so I’m attempting to run all of these updates through the Update action. The one catch is that in the Wizard view, I need to make a call to the Stripe API. So I have that Stripe call in the Update controller. But now when the user tried to update their account on the Settings or Account views, the update controller is calling the Stripe API, which obviously is not what I’m going for.

So what I’ve attempted to do, is to insert a conditional to check if one of the Wizard parameters(:total_value) is being passed in, and if it is, to charge to Stripe. If it’s not, then just update the user data. But I haven’t been able to get that to work, it’s just updating the user and not charging to Stripe.

Is this the right direction to be separating these updates? Or should I be creating custom actions within the Users controller? How does this work?

users_controller

def update
  if !params[:total_value].nil?
    if @user.update_attributes(params[:user])
      # flash[:success] = "Profile updated"
      sign_in @user
      # Value input by the user (in dollars)
      @userPrice = params[:user][:total_value]
      # Send full price in cents to Stripe
      @stripePrice = @userPrice.to_i * 100

      Stripe::Charge.create(
        :amount => @stripePrice,
        :currency => "usd",
        :card => params[:user][:stripe_card_token],
        :description => "Charge for service"
      )  
      redirect_to success_path
      flash[:success] = "Hurray!"
    else
      flash.now[:notice] = "Can not be saved, please enter information."
      render :new
    end
  elsif 
    if @user.update_attributes(params[:user])
      sign_in @user
      flash[:success] = "Profile updated"
      redirect_to account_path
    else
      flash[:error] = "Error"
    end
  end    
 end

wizard/show.html.erb

  <%= form_for(@user) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>
        <%= f.text_field :total_value, placeholder: "0", :class => 'amount' %>

        <%= f.label :name %>
        <%= f.text_field :name, required: "required" %>

        <%= f.label :address_1, "Address" %>
        <%= f.text_field :address_1, required: "required" %>

        <%= f.label :address_2, "Address line 2" %>
        <%= f.text_field :address_2 %>

        <%= f.label :city, "City" %>
        <%= f.text_field :city, required: "required" %>

        <%= f.label :state, "State" %>
        <%= f.text_field :state, required: "required" %>

        <%= f.label :zip, "Zip code" %>
        <%= f.text_field :zip, required: "required" %>

        <%= f.hidden_field :stripe_card_token %>

        <%= label_tag :card_number, "Credit Card Number " %>  
        <%= text_field_tag :card_number, nil, name: nil %>  

        <%= label_tag :card_code, "Security Code on Card (CVV)" %>  
        <%= text_field_tag :card_code, nil, name: nil %>  
       <%= label_tag :card_month, "Card Expiration" %>  
        <%= select_month nil, {add_month_numbers_true: true}, {name: nil, id: "card_month"}%>  
        <%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year"}%>  
        <%= f.submit "Update your shipping information", class: "btn btn-large btn-primary" %>

    <% end %>

users/shipping.html.erb

      <%= form_for(@user) do |f| %>
        <%= render 'shared/error_messages', object: f.object %>
            <%= f.label :name %>
            <%= f.text_field :name %>

            <%= f.label :address_1, "Address" %>
            <%= f.text_field :address_1 %>

            <%= f.label :address_2, "Address line 2" %>
            <%= f.text_field :address_2 %>

            <%= f.label :city, "City" %>
            <%= f.text_field :city %>

            <%= f.label :state, "State" %>
            <%= f.text_field :state %>

            <%= f.label :zip, "Zip code" %>
            <%= f.text_field :zip %>  

            <%= f.submit "Update your shipping information", class: "btn btn-large btn-primary" %>
      <% end %>

users/account.html.erb

  <%= form_for(@user) do |f| %>
    <%= render 'shared/error_messages', object: f.object %>
        <%= f.label :name %>
        <%= f.text_field :name %>

        <%= f.label :email %>
        <%= f.text_field :email %>

        <%= f.label :password %>
        <%= f.password_field :password %>

        <%= f.label :password_confirmation, "Confirm Password" %>
        <%= f.password_field :password_confirmation %>

        <%= f.submit "Save changes", class: "btn btn-large btn-primary" %>

  <% end %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:10:15+00:00Added an answer on June 17, 2026 at 1:10 pm

    I see two problems. First is that your:

    if !params[:total_value].nil?

    should be

    unless params[:user][:total_value].nil? (I personally prefer unless to if !...)

    as stated in the comments by Nishant. Second you have an elsif and the end of that condition, without it checking anything. Just an else would suffice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a User model that has the following default_scope: default_scope where(account_id: Account.current_account.id) If
So I have a model that includes: class Place(models.Model): .... created_by = models.ForeignKey(User) My
I have a data model that includes common columns like addedBy, editedby (user), addedDate,
I have a User model that has many posts. Im trying to render the
I have a user model that requires the user to change their password every
I have a model that has a ForeignKey to the built-in user model in
I have a field on my User model that is protected because it determines
So I have a method in my User model that tries to determine if
I have a model that looks like this: class Invite(models.Model): user = models.ForeignKey(User) event
I have a user model on which I check to make sure that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.