Question about MVC

Hi all,

I have a question about a MVC-“problem” and how to handle so a case.

I want page which lists some users. You can add users with a
dropdown-list.
So something like:


%h2 Selected users
user1
user2

%h2 Add an extra user
user3
user4
user5

I now have:

%h2 Selected users
user1
user2

%h2 Add an extra user
user3
user4
user5

What is a nice/clean way to remove the selected users from the
dropdown-list?
I now have this ruby-code in my rhtml:

collection_select(‘new_declaration_payer’, ‘user_id’, @users, ‘id’,
‘fullname’, {:prompt => ‘-- Selecteer een betaler --’}

Thanks in advance!

Leon B. wrote:

Hi all,

I have a question about a MVC-“problem” and how to handle so a case.

Hi Leon. Welcome to the forum.

What you described doesn’t sound like an MVC problem. It sounds more
like a Rails, possibly even a JavaScript issue.

I want page which lists some users. You can add users with a
dropdown-list.
So something like:


%h2 Selected users
user1
user2

%h2 Add an extra user
user3
user4
user5

I now have:

%h2 Selected users
user1
user2

%h2 Add an extra user
user3
user4
user5

I might be missing it, but I don’t see the difference between the two
diagrams. Care to elaborate?

What is a nice/clean way to remove the selected users from the
dropdown-list?

If all you want to do is remove users from your list, the best place to
do so would be in your controller. I see you have a @users object. Try
something like…

@users = @users.map { |user| user.meets_some_condition }

If instead you want to dynamically add/remove users from a drop-drop
list, you’re going to need JavaScript. I’d suggest jQuery.

Hope that helps.

  • Rabbit