I
I
Ilnar252015-11-05 02:20:42
Ruby on Rails
Ilnar25, 2015-11-05 02:20:42

How to pass an array through routes.rb in Rails4?

I can not determine what is the problem in the database request, an error in the router or in the helper call? According to the logs, I suspect a router. Help!
Here is an example:
/-/-/-/-/-/.html.haml
...
- all_users_id = message_incoming | message_outgoing
- all_users_id.delete(user.id)
%h4= link_to "My Contacts", all_users_path(my_users_id: all_users_id)
routes.rb
get
'messages/all_my_users/:my_users_id', to: 'messages#all_my_users', as: ' all_users'
_____________________________________________________________________________
messages_controller.rb
def all_my_users
@my_users = User.where("id = ?", params[:
end
________________________________________________________________________
Started GET "/messages/all_my_users/7%2F8" for 127.0.0.1 at 2015-11-05 02:02:23 +0300
Processing by MessagesController#all_my_users as HTML
Parameters: {"my_users_id"=>"7/8 "}
User Load (2.8ms) SELECT "users".* FROM "users" WHERE (id = '7/8')
PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: "7/8"
LINE 1: SELECT "users".* FROM "users" WHERE (id = '7/8')
^
: SELECT "users".* FROM "users" WHERE (id = '7/8')
Rendered messages/all_my_users.html.haml within layouts/application (4.5ms)
Completed 500 Internal Server Error in 8ms (ActiveRecord: 2.8ms)
ActionView::Template::Error (PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: "7/8"
LINE 1: SELECT "users".* FROM "users" WHERE (id = '7/8')
^
: SELECT "users".* FROM "users" WHERE (id = '7/8')):

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Andreev, 2015-11-05
@b0nn1e

there is a special tag for formatting the code.
And according to your error, it is clearly written to you - ERROR: invalid input syntax for integer: "7/8"

C
caution, 2015-11-05
@caution

7/8? :)

V
vsuhachev, 2015-11-05
@vsuhachev

You cannot pass an array in a URL without additional gestures
. Usually, in Rails, arrays are passed in parameters like this:
http://myurl?array_name[]=7&array_name[]=8

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question