administrate
administrate copied to clipboard
Does not play along with model named Host
-
What were you trying to do? it does not play along with a model named Host
-
What did you end up with (logs, or, even better, example apps are great!)? it looks like error is happening when it's trying to build a link in a collection view
link_to[actionview (7.2.2) lib/action_view/helpers/url_helper.rb]
209
html_options, options, name = options, name, block if block_given?
options ||= {}
html_options = convert_options_to_data_attributes(options, html_options)
url = url_target(name, options)
html_options["href"] ||= url
content_tag("a", name || url, html_options, &block)
end
>> options
=> #<ActionController::Parameters {"host"=>#<ActionController::Parameters {"order"=>:id, "direction"=>:asc} permitted: false>} permitted: true>
>>
>> url_target(name, options)
!! #<ActionController::UnfilteredParameters: unable to convert unpermitted parameters to hash>
>>
- What versions are you running?
- Rails 7.2.2
- administrate 0.20.1
I wonder if the URL builder considers host to be a reserved value or something.
If you create a normal Rails controller, do you see the same behaviour?
It is not a reserved word, we have HostsController working with Host model in the main application. I suspect administrate overwrites host variable in a controller or interferes in some similar way
Yeah, quite likely. Would you be able to put together an example app I can clone and try out?
I'm not sure why it would be the case that this fails, but it shouldn't.
@nickcharlton it took me a while to put this together but here's a sample project https://github.com/jurgens/administrate-host-example
I created two identical models - Host and Chef in a readme you can find an error message that pops up with you try to navigate to admin/hosts
would really appreciate a workaround, even if it is a monkey-patch :)
@jurgens @nickcharlton Hey, I have a solution for this bug.
I believe that it can happen with other names too, like domain or port which is quite annoying.
The bug happens in the app/views/administrate/application/_collection.html.erb view file.
There is a line that calls link_to helper with parameters that look like {"host" => {"order" => :id, "direction" => :asc}}.
Some method inside Rails thinks that host corresponds to a URL host and not to a URL parameter called host.
There is an easy way to solve it: wrap these parameters into a hash params: ... before calling the link_to method. This way Rails will understand that it's not a url host value.
Here is a PR that fixes the bug in administrate: https://github.com/thoughtbot/administrate/pull/2865
@jurgens if you want to have a local workaround, you can generate the collection view file in your repo and then correct the bug a similar way that I did in my PR.
@endenis many thanks, will try it out today!
Should be fixed now on main after merging https://github.com/thoughtbot/administrate/pull/2865. Thank you all!