Rutul Dave

Joined

1,160 Experience
10 Lessons Completed
0 Questions Solved

Activity

Posted in Devise Masquerade as another User Discussion

hey Georges-Alexandre Haines,

I was looking to do something similar and best way I found is to create a "field" in the list view of RailsAdmin for the model.

Something like this:

      field :masquerade do
        formatted_value do
          output = []
          o = bindings[:object]
          v = bindings[:view]
          output << "\<a href=\"/user/masquerade/#{o.id}\"\>Login as</a>"
          v.raw output.join("&nbsp;")
        end
      end

So you can customize the view for what you see in the model's list view in RailsAdmin by doing this in the model:

class User < ApplicationRecord
...
...

  rails_admin do
    list do
      field :id
      ...
    end
  end
end

I have used keyword arguments for some of my methods before, but haven't really thought about why not use it for all methods with arguments?

Seems like there is no good reason to have the caller ever know the correct ordering for the arguments.

If verbosity of the code is the only issue with keyword arguments, is there a good reason to not use keyword arguments for all your methods?

More on keyword arguments from Thoughtbot - https://robots.thoughtbot.com/ruby-2-keyword-arguments

Thanks. It will be useful to have a + Add link as well.

A solution that works, but feels/looks "hacky" is hiding the "add another" link and then trigger the click to that link when the enter key is pressed.

$("#nestedModelAttribute").keyup(function (e) {
if (e.keyCode == 13) {
$('.add-another').trigger("click");
}
});

I got cocoon working as well as I want.
Next though, I want to use the capabilities of cocoon and customize a bit.

For example, instead of having a 'Add another' link under the nested model, I want to to add the input field for the nested model when the user presses the enter key after adding a record for the nested model. So I want to trigger link_to_add_association when 'enter' key is pressed.

Any suggestions on how best to do that?

Thanks Chris. I tried out cocoon and it was a pretty straightforward to use. I guess I will go with the safe answer on this project :-).

I am not sure what the consensus is on the best approach to handling nested model forms is.
The solution in https://gorails.com/episodes/forum-nested-attributes-and-fields-for can work, but doesn't seem like it can scale.

Chris mentioned cocoon - https://github.com/nathanvda/cocoon

And in the comments, Daniel Kehoe seems to suggest using ActiveForm.

How do folks generally do nested forms?

Nice episode Chris. A small note that might help people new to adding initializers is that you need to restart your app after you add the omniauth initializer so that localhost:3000/auth/twitter works as expected. Might throw a few people off if they follow your steps along and forget to restart the app.