[openstreetmap/openstreetmap-website] ActionView::Template::Error (undefined method `redacted?' for nil:NilClass) in app/views/browse/_relation_member.html.erb (#1988)
Simon Gabyshev
notifications at github.com
Mon Sep 10 07:43:02 UTC 2018
So I'm trying to run OSM in docker with latest master.
I downloaded and imported database for Monaco because it's small (http://download.geofabrik.de/europe/monaco-latest.osm.pbf)
I'm running it on top of `phusion/passenger`.
Dockerfile looks like:
```Dockerfile
FROM phusion/passenger-ruby24
COPY --chown=app:app ./osm /home/app/osm
WORKDIR /home/app/osm
RUN echo "gem 'tzinfo-data'" >> Gemfile
RUN bundle install
RUN apt-get update && apt-get install -y libv8-dev osmosis postgresql-client
# needed for successful assets precompile
RUN cp config/example.application.yml config/application.yml
RUN cp config/example.database.yml config/database.yml
RUN bundle exec rake i18n:js:export
RUN bundle exec rake assets:precompile
RUN chown -R app:app /home/app/osm/tmp
RUN rm -f /etc/service/nginx/down
RUN rm /etc/nginx/sites-enabled/default
ADD osm.conf /etc/nginx/sites-enabled/osm.conf
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN curl -o /home/app/monaco.osm.pbf http://download.geofabrik.de/europe/monaco-latest.osm.pbf
ADD ./docker/Application/bin/configure.sh /etc/my_init.d/configure.sh
ADD ./docker/Application/bin/migrate.sh /home/app/migrate.sh
RUN chmod +x /etc/my_init.d/configure.sh && chmod +x /home/app/migrate.sh
CMD ["/sbin/my_init"]
```
`configure.sh` configures `database.yml` and `application.yml` and `migration.sh` create functions, extensions and migrate data using osmosis:
```shell
osmosis --read-pbf /home/app/monaco.osm.pbf --log-progress --write-apidb database=$POSTGRES_DB host=$POSTGRES_HOST:$POSTGRES_PORT validateSchemaVersion=no user=$POSTGRES_USER password=$POSTGRES_PASSWORD dbType=postgresql
```
I see an error when trying to open relation `/relation/2220322`:
```
Started GET "/relation/2220322" for 172.27.0.1 at 2018-09-10 06:23:11 +0000
Processing by BrowseController#relation as HTML
Parameters: {"id"=>"2220322"}
Rendering browse/feature.html.erb within layouts/map
Rendered collection of browse/_tag.html.erb [145 times] (23.5ms)
Rendered browse/_tag_details.html.erb (30.8ms)
Rendered browse/_common_details.html.erb (43.1ms)
Rendered collection of browse/_relation_member.html.erb [36 times] (70.3ms)
Rendered browse/_relation.html.erb (120.0ms)
Rendered browse/feature.html.erb within layouts/map (127.2ms)
Completed 500 Internal Server Error in 322ms (ActiveRecord: 51.4ms)
ActionView::Template::Error (undefined method `redacted?' for nil:NilClass):
1: <%
2: member_class = link_class(relation_member.member_type.downcase, relation_member.member)
3: linked_name = link_to printable_name(relation_member.member), { :action => relation_member.member_type.downcase, :id => relation_member.member_id.to_s }, :title => link_title(relation_member.member), :rel => link_follow(relation_member.member)
4: type_str = t '.type.' + relation_member.member_type.downcase
5: %>
app/helpers/browse_helper.rb:35:in `link_class'
```
The error happening in `app/views/browse/_relation_member.html.erb` because helper method `app/helpers/browse_helper.rb` trying to call `redacted?`:
```ruby
def link_class(type, object)
classes = [type]
if object.redacted?
classes << "deleted"
else
classes += icon_tags(object).flatten.map { |t| h(t) }
classes << "deleted" unless object.visible?
end
classes.join(" ")
end
```
`_relation_member.html.erb` rendered by `_relation.html.erb`:
```ruby
<% unless relation.relation_members.empty? %>
<h4><%= t '.members' %></h4>
<ul><%= render :partial => "relation_member", :collection => relation.relation_members %></ul>
<% end %>
```
But in the console I found that not every `relation_member` has a `member`:
```ruby
Loading production environment (Rails 5.2.0)
2.4.4 :001 > r = Relation.preload(:relation_tags, :containing_relation_members, :changeset => [:changeset_tags, :user], :relation_members => :member).find("2220322")
=> #<Relation id: 2220322, changeset_id: 0, timestamp: "2018-05-04 10:30:32", visible: true, version: 25>
2.4.4 :002 > r.relation_members.empty?
=> false
2.4.4 :003 > r.relation_members[25].member
=> nil
2.4.4 :004 > r.relation_members[0].member
=> #<Relation id: 5986436, changeset_id: 0, timestamp: "2016-05-18 07:21:05", visible: true, version: 3>
```
Which looks like a bug to me. I would be happy to send PR to fix it but I have no idea what is the logic should be.
Shall we just skip `relation_members` without `member`s ?
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/issues/1988
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20180910/32970ecd/attachment.html>
More information about the rails-dev
mailing list