last day (15 days later) » 

3:29 PM
0
A: How to use a form from another controller to set a value that has a has_many :through relation in Rails4?

oreoluwaI'm not totally sure, but I think this should work: <% if user_signed_in? %> <%= form_for current_user, url: edit_user_registration_path do |f| %> <div class="form-group"> <%= f.collection_select(:current_company, current_user.moderated_companies, :id, :name, prompt: "Select a company") %

 
Dear @oreoluwa, thank you for your reply. I'm getting a new error: Could not find the source association(s) "moderated_company" or :moderated_companies in model ModeratorConnection. Try 'has_many :moderated_companies, :through => :moderator_connections, :source => <name>'. Is it one of user or company? It seems like my associations aren't properly aligned yet. Any ideas on how to add the proper assiociations?
 
updated my answer, hope that works
 
Yes, much better! Still an error (No route matches [PATCH] "/users/edit"). Do I have to manually have to add a Patch-route to my routes?
 
that's due to the path you're setting for your form. Do you have a custom users_controller?
 
Yes, I do. Is that something I shouldn't do?
 
3:29 PM
If you have the users_controller, change your path to edit_user_path(current_user)
 
I hope it's okay that I moved the discussion into a chat. I'm already very glad with your help so far! That's why I accepted it already.
But even with the last path change, it doesn't work yet. I also tried it with edit_user_registration_path(current_user)
If you can't help me out from this point, I'll fully understand.
 
is this project on Github or something?
I could look at it
 
3:55 PM
Ai, no it isn't
 
Oh
what actions are in your users_controller?
 
Only a index method:
def index
@users = User.all #where{|user| user.companies == current_user.companies}
authorize @users
@groups = Group.all
@user = User.new
end
 
Check this gist for a rough implementation: gist.github.com/andela-oakinniranye/…
 
4:17 PM
Wow, thanks for that! I'm still getting an error: No route matches [PATCH] "/users/edit.3"
Could it be something in my routing?
 
4:35 PM
could you add a resources :users, only: [:edit, :index]. Note that this is just a rough implementation, to guide your thought in the development, it may not the best approach. Can't really determine the best at the moment, as I'm not totally sure we should be toggling the current_company only within the users_controller#edit.
 
I fully understand that. I'm in a tram at the moment and will test it within a few hours.
 
 
4 hours later…
8:15 PM
Ai, it's a pity: still the same error.
 

last day (15 days later) »