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

  • SEARCH
  • Home
  • 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 8625635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:50:15+00:00 2026-06-12T07:50:15+00:00

Right now I’m trying to build an app which has the ability to search

  • 0

Right now I’m trying to build an app which has the ability to search for phone numbers, buy them, and record the transaction to a database.

The way I thought to do it was to have two controllers– (1) the find_numbers controller takes paramaters and searches for numbers. And (2) the phones controller buys the chosen number and saves the parameters to the database.

Here’s a diagram of what I’m trying to do.

http://www.stepanp.com/search-and-buy.jpg

With the help of a fellow stackoverflower, I was able to fix a bunch of the errors, but for some reason, when I POST from find_numbers/show to PhonesController#create, I get the error

ActiveModel::MassAssignmentSecurity::Error in PhonesController#create

Can’t mass-assign protected attributes: :original_number, :name, :twilio_number

I think it might have to do with the way my form is laid out, because the Phone Model does have attr_accessible to these values.

Here’s the find_numbers/show form

<%= @numbers.each do |number| %>

    <%= form_tag(:controller => "phones", :action => "create" ) do %>
        <%= hidden_field "phone[:original_number]", params[:original_number] %>


    <%= hidden_field "phone[:name]", params[:name] %>
        <%= hidden_field "phone[:twilio_number]",  number.phone_number %>

        <div class="found_list">
            <div class="found_phone_number">
                <%= label_tag("phone[:number]", number.friendly_name) %>
            </div>
            <div class="choose_found_number">
             <%= submit_tag("Choose This Number", :class => "btn btn-large btn-success") %>
            </div>
        </div>
            <hr>
    <% end %>
<% end %

It might have something to do with adding the phone[] around the values

Here’s the PhoneController#Create Action

def create
    @user = current_user
    @phone = @user.phones.new(params[:phone])
    client = Twilio::REST::Client.new(@user.twilio_account_sid, @user.twilio_auth_token)
    number = client.account.incoming_phone_numbers.create(
                   :phone_number => params[:twilio_number])
    if @phone.save && number.present?
      flash[:success] = "Phone Number Created!"
      redirect_to user_path
    else
      render new_find_number_path
      flash[:error] = "It looks like there were errors with the submission"
    end
end

And here’s the Phone Model

# == Schema Information
#
# Table name: phones
#
#  id              :integer          not null, primary key
#  name            :string(255)
#  twilio_number   :string(255)
#  original_number :string(255)
#  user_id         :integer
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#

class Phone < ActiveRecord::Base

  attr_accessible :original_number, :user_id, :name, :twilio_number
  belongs_to :user

  validates :name, presence: true
  validates :twilio_number, presence: true
  validates :original_number, presence: true
  validates :user_id, presence: true

  default_scope order: 'phones.created_at DESC'

end

I think the “phone[:attribute]” in the form has something to do with this — though if we didn’t put it that way, for some reason the create action would not understand that the :name attribute that was POSTED was for the phone model.

Any help on this would be greatly appreciated

  • 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-12T07:50:16+00:00Added an answer on June 12, 2026 at 7:50 am

    I couldn’t figure out why this was happening, but I avoided it all together by rendering phones/new instead, and using form_for(@phone) rather than form_tag

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

Sidebar

Related Questions

Right now I have some TabItems in my App which are implicitly styled. I
Right now I'm asking the user for two numbers. I'm trying to print the
Right now, I've just some code which fetches the picture from the URL directly.
Right now, the label for my Activity has the name of the current Activity.
Right now I am only trying to get my getline() function to work. I
Right now I'm working on a Internet Explorer add on which is supposed to
right now I have a huge Solution in which we use javascript alerts via
Right now I have: Time.strftime(%I:%M%p) which gives me the hr:min AM/PM format which I
Right now, I have developed an android app that is available free on the
Right now I detect the credit card type based upon the first four numbers

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.