railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.89k stars 2.26k forks source link

Rails_admin does not render partials from app/views/rails_admin/main/ #1877

Closed desmondrawls closed 5 years ago

desmondrawls commented 10 years ago

This issue is related to https://github.com/sferik/rails_admin/issues/787.

I am trying to use a partial to customize my edit view in rails_admin. In config/initializers/rails_admin.rb I have:

RailsAdmin.config do |config|

  config.model 'Album' do
    edit do
      field :promotion do
        partial :hello_world
      end
    end
  end

end

I have also tried the other syntax that can be found on the rails_admin wiki:

RailsAdmin.config do |config|

  config.model 'Album' do
    edit do
      field :promotion do
         def render
            bindings[:view].render :partial => carrierwave.to_s, :locals => {:field => self, :form => bindings[:form]}
         end
      end
    end
  end

end

I am locating my partial at app/views/rails_admin/main/_hello_world.html.erb with the content:

<h3>Hello World!</h3>

After restarting my server nothing shows up in the edit view except for an empty 'promotion' field.

Rails_admin had a github issue for this. The discussion seemed inconclusive and the issue was closed before anyone confirmed that the solution worked for them. The issue can be viewed here:

https://github.com/sferik/rails_admin/issues/787

The moderator creates a spec for the issue and then closes it. The spec can be viewed at the very bottom of this file:

https://github.com/sferik/rails_admin/blob/59da00303ca2162089b7dd7653a2f19494fb74b4/spec/unit/config/fields/base_spec.rb

My concern with the spec is that it does not test where rails_admin looks for the partial. According to the rails_admin wiki partials should be location in app/views/rails_admin/main/

Please help me understand what I'm doing wrong or, at least, please assure me that rails_admin does not still have an issue here. I'm using Rails 4 and Ruby 2.0.0

bbenezech commented 10 years ago

First solution should work.

Second should read:

render do
   bindings[:view].render :partial => "rails_admin/main/_hello_world", :locals => {:field => self, :form => bindings[:form] }
end

787 is not related (render was not an option at the time, it has changed meanwhile)

shingonoide commented 9 years ago

I think, this issue should be reopened because it's not working in Rails 4 with Ruby 2.1.5 for me either.

as simple doesn't works:

RailsAdmin.config do |config|

  config.model 'Model' do
    show do
      field :field_name do
        partial :partial_name
      end
  end

end

with partial in app/views/rails_admin/main/_partial_name.html.haml

I guess if the partial doesn't exist should thrown a error what is not happens either.

drubin commented 8 years ago

@shingonoide According to https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/config/fields/base.rb#L112

The partial is never actually called for the show method.

The following works with rails 4.X and railsadmin (current release), hope this helps.

#ruby
show do
      field :lat do
        formatted_value do
          bindings[:view].render :partial => "rails_admin/main/partial", :locals => {:field => self, :object => bindings[:object] }
        end
      end
    end
amicming commented 7 years ago

This one NOT working with rails_admin-1.1.1.

iSarCasm commented 7 years ago

Seems to be fixed now

za4emnik commented 7 years ago

In my case formatted_value not work. I used pretty_value. For example:

pretty_value do
  bindings[:view].render partial: 'images_gallery', locals: {object: self}
end

rails_admin 1.2 ruby 2.3.0

costa commented 5 years ago

latest everything: ping!

jayithiel commented 4 years ago

I was running into this issue as well.

# does not render partial
field :field_name do
  partial 'partial_name'
end

# rendered partial but `form` was nil
pretty_value do
  bindings[:view].render partial: 'images_gallery', locals: {object: self}
end

# working with `form` available
field :field_name do
  pretty_value do
    bindings[:view].render partial: partial.to_s, locals: {:field => self, :form => bindings[:form]}
  end
end

rails_admin 2.0 rails 5 ruby 2.6

What's interesting is I use

field :field_name do
  partial 'partial_name'
end

elsewhere in the codebase and it works fine