Ruby on Rails Tuesday, February 24, 2015

On 24 February 2015 at 12:19, Sai Ch <lists@ruby-forum.com> wrote:
> Rails 4 and PostgreSQL Arrays:
>
> Can anybody solve the bellow problem
>
> UserModel:
> class User < ActiveRecord::Base
> has_many :courses, dependent: :destroy
> end
> Course Model:
> class Course < ActiveRecord::Base
> belongs_to :user
> end
> def course_params
> params.require(:course).permit(:name, ..., user_id: [])
> end
> Course/ _form.html.erb file contains:
> <%= hidden_field_tag(:user_id, @course.user_id) %>
> class CreateCourses < ActiveRecord::Migration
> def change
> create_table :courses do |t|
> t.integer :user_id, :array => true

Why have you got user_id as an array?

Colin


> t.text :name, default: " "
> t.text :description, default: " "
> t.text :welcome_note, default: " "
> t.text :promotional_text, default: " "
> t.string :phone_number, default: " "
> t.string :restaurant_phone_number, default: " "
> t.timestamps
> end
> end
> end
> ................................................................................................
>
> Started POST "/courses" for 127.0.0.1 at 2015-02-24 17:07:07 +0530
> Processing by CoursesController#create as HTML
> Parameters: {"utf8"=>"✓",
> "authenticity_token"=>"vXo+MeMi0TedrcIO3F+m2X6uMDHuH/deDvj3yKbtuBc=",
> "course"=>{"name"=>" kvanadev6", "line1"=>" ", "line2"=>" ", "city"=>"
> ", "state"=>" ", "zip"=>" ", "latitude"=>"0.0", "longitude"=>"0.0",
> "description"=>" ", "welcome_note"=>" ", "promotional_text"=>" ",
> "phone_number"=>" ", "restaurant_phone_number"=>" "}, "commit"=>"Create
> Course"}
> User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id"
> = 2 ORDER BY "users"."id" ASC LIMIT 1
> Course: #<Course id: nil, user_id: 2, name: " kvanadev6", description: "
> ", welcome_note: " ", promotional_text: " ", phone_number: " ",
> restaurant_phone_number: " ", created_at: nil, updated_at: nil,
> main_image_file_name: nil, main_image_content_type: nil,
> main_image_file_size: nil, main_image_updated_at: nil,
> restaurant_menu_image_file_name: nil,
> restaurant_menu_image_content_type: nil,
> restaurant_menu_image_file_size: nil, restaurant_menu_image_updated_at:
> nil, line1: " ", line2: " ", city: " ", state: " ", zip: " ", latitude:
> 0.0, longitude: 0.0>
> (0.4ms) BEGIN
> SQL (1.3ms) INSERT INTO "courses" ("created_at", "name",
> "updated_at", "user_id") VALUES ($1, $2, $3, $4) RETURNING "id"
> [["created_at", "2015-02-24 11:37:07.762549"], ["name", " kvanadev6"],
> ["updated_at", "2015-02-24 11:37:07.762549"], ["user_id", 2]]
> PG::InvalidTextRepresentation: ERROR: malformed array literal: "2"
> DETAIL: Array value must start with "{" or dimension information.
> : INSERT INTO "courses" ("created_at", "name", "updated_at", "user_id")
> VALUES ($1, $2, $3, $4) RETURNING "id"
> (0.6ms) ROLLBACK
> Completed 500 Internal Server Error in 14ms
> ...........................................................................................................................
>
> PG::InvalidTextRepresentation - ERROR: malformed array literal: "2"
> DETAIL: Array value must start with "{" or dimension information.
> :
> ...............................................
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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/a75c06b7a35decdc196f57a01ccc1448%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
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/CAL%3D0gLtn790QC-rxVYnKYF_a2P2fp1WhtoPpWZqWQbF_EqdBdg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment