Passing data from a view to another controller using link_to - Ruby on Rails
I am trying to send this user id from my view to a controller, now the point is that the value is being passed correctly to the controller (manage_users_controller) corresponding to that view, but it is not being sent to another controller (server_management_controller)
u.column :name => "Action" do |user|
#Works fine
link_to('Edit', edit_manage_user_path(user.id)) + " | " +
#This call does not send the value
link_to('Assign Servers', edit_server_management_path(user.id))
end
Controller action (server_management_controller):
def show
if @uid == 1 #The value being sent from the view
@servers_grid = initialize_grid(Server)
@servers = Server.all
@name = current_user[:username]
@email = current_user[:email]
render 'index'
end
end
def edit
@uid = params[:id]
show
end
Another point worth mentioning is that the IS value is added to the URL when the Assign Server link is clicked, i.e. xyz.com/server_management/1/edit
Any help would be appreciated.
--- --- solvable
One tip
The parameter comes in as a string, so make sure you don't treat it as a whole at once.
source to share
Any request parameter you pass to the Rails Url Helper, for example:
edit_manage_user_path(anyname: user.id)
can be accessed from the called action like this
params[:anyname]
anyname
of course just an example.
If this parameter is already part of the URL that Rails generates for you, it is most likely :id
. You can watch this by executing rake routes
which will provide you with a complete list of all routes configured in your application.
Does this answer your question?
source to share