Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Paperclip and has_friendly_id support #67

Closed
wants to merge 13 commits into from

2 participants

@capotej

I added support for file uploads (paperclip) and fixed some errors when used with has_friendly_id. Thanks for writing a great plugin!

@neerajdotname neerajdotname commented on the diff
app/views/admin_data/crud/misc/_modify_record.html.erb
@@ -3,14 +3,14 @@
<h3>Modify Record</h3>
<div style='padding-left:15px'>
<p>
- <%= link_to 'Edit', admin_data_edit_path(:klass => klass.name.underscore, :id => model) %>
+ <%= link_to 'Edit', admin_data_edit_path(:klass => klass.name.underscore, :id => model.id) %>
@neerajdotname Owner

Any particular reason why model.id is needed in all these cases.

@capotej
capotej added a note

When using friendly_id (https://github.com/norman/friendly_id), it overrides to_param on the models, so /model/edit/123 becomes /model/edit/model-friendly-name, which admin_data can't find, however, if you use .id explicitly, it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@neerajdotname

Thanks for the pul request. I will have to write a cucumber test for the if condition that you added. Once the test is done then I will merge it.

On a lighter note I thought I was the only guy using this gem since rails_admin is so popular.

@capotej

If I knew how to test it I would, I was just pushing and testing it live with my app (hence all the commits), I'll look forward to reading the test though.

I actually found your gem to be a little better than rails_admin because it was light and simple, rails_admin hangs when loading large associations (when I don't even care about association editing to begin with!). So, good job on keeping it simple.

@neerajdotname

To make admin_data work with friendly_id see the solution presented here

https://github.com/neerajdotname/admin_data/issuesearch?state=open&q=friendly#issue/65

In this way we don't need to have .id everywhere .

If this solution works for you then send another pull request only for paperclip support.

@neerajdotname

We are no longer supporting admin_data. Thanks for the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
4 app/controllers/admin_data/crud_controller.rb
@@ -45,7 +45,7 @@ def update
if @model.update_attributes(model_attrs)
format.html do
flash[:success] = "Record was updated"
- redirect_to admin_data_path(:id => @model, :klass => @klass.name.underscore)
+ redirect_to admin_data_path(:id => @model.id, :klass => @klass.name.underscore)
end
format.js { render :json => {:success => true}}
else
@@ -67,7 +67,7 @@ def create
else
format.html do
flash[:success] = "Record was created"
- redirect_to admin_data_path(:id => @model, :klass => @klass.name.underscore)
+ redirect_to admin_data_path(:id => @model.id, :klass => @klass.name.underscore)
end
format.js { render :json => {} }
end
View
4 app/views/admin_data/crud/edit.html.erb
@@ -12,8 +12,8 @@
<div class="content rounded">
<div class="inner umbrella">
- <% url = admin_data_path(:klass => @klass.name, :id => @model)
- html_options = {:class => 'form', :method => :put} %>
+ <% url = admin_data_path(:klass => @klass.name, :id => @model.id)
+ html_options = {:class => 'form', :method => :put, :multipart => true} %>
<%= form_for @model, :as => @klass.name.underscore.to_sym, :url => url, :html=> html_options do |f| %>
<%= render 'admin_data/shared/flash_message', :model => @model %>
<%= render 'admin_data/crud/misc/form', :klass => @klass, :f => f %>
View
17 app/views/admin_data/crud/misc/_form.html.erb
@@ -1,4 +1,20 @@
<% @columns.each do |col| %>
+<% if col.name.include?('file_name') %>
+<% attachment_name = col.name.gsub('_file_name','') %>
+<% if @model.respond_to?(attachment_name.to_sym) %>
+ <div class='col_box'>
+ <span class='col_name'><%= col.name %></span>
+ <span class='col_type'>[file upload]</span>
+ </div>
+ <div class='data'>
+ <input type="file" name="<%= klass.to_s.downcase %>[<%= attachment_name %>]" />
+ Original: <%= image_tag @model.send(attachment_name.to_sym).url %><br/>
+ <% @model.send(attachment_name.to_sym).styles.keys.each do |key| %>
+ <%= key.to_s.gsub(':','').capitalize %>: <%= image_tag @model.send(attachment_name.to_sym).url(key) %><br/>
+ <% end %>
+ </div>
+<% end %>
+<% else %>
<div class='col_box'>
<span class='col_name'><%= col.name %></span>
<span class='col_type'>[<%= col.type.to_s %>]</span>
@@ -7,6 +23,7 @@
<%= form_field(klass, @model, col, f).html_safe %>
</div>
<% end %>
+<% end %>
<% if AdminData::ActiveRecordUtil.new(klass).declared_habtm_association_names.any? %>
<div class='data'>
View
6 app/views/admin_data/crud/misc/_modify_record.html.erb
@@ -3,14 +3,14 @@
<h3>Modify Record</h3>
<div style='padding-left:15px'>
<p>
- <%= link_to 'Edit', admin_data_edit_path(:klass => klass.name.underscore, :id => model) %>
+ <%= link_to 'Edit', admin_data_edit_path(:klass => klass.name.underscore, :id => model.id) %>
@neerajdotname Owner

Any particular reason why model.id is needed in all these cases.

@capotej
capotej added a note

When using friendly_id (https://github.com/norman/friendly_id), it overrides to_param on the models, so /model/edit/123 becomes /model/edit/model-friendly-name, which admin_data can't find, however, if you use .id explicitly, it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
</p>
<p>
- <%= link_to 'Delete', admin_data_del_path(:klass => klass.name.underscore, :id => model) ,
+ <%= link_to 'Delete', admin_data_del_path(:klass => klass.name.underscore, :id => model.id) ,
{ :confirm => ' You are deleting (not destroying) a record. Are you sure?', :method => :delete} %>
</p>
<p>
- <%= link_to "Destroy", admin_data_path(:klass => klass.name.underscore, :id => model),
+ <%= link_to "Destroy", admin_data_path(:klass => klass.name.underscore, :id => model.id),
{ :confirm => 'You are destroying a record. Are you sure?', :method => :delete} %>
</p>
</div>
View
2  app/views/admin_data/search/search/_listing.html.erb
@@ -23,7 +23,7 @@
<% columns_order(klass).each do |column| %>
<td>
<% if (column == klass.primary_key) %>
- <%= link_to(record.to_param.to_s, admin_data_path(:klass => klass.name.underscore, :id => record)) %>
+ <%= link_to(record.to_param.to_s, admin_data_path(:klass => klass.name.underscore, :id => record.id)) %>
<% else %>
<%=h get_value_for_column(column_native(klass, column), record) %>
<% end %>
Something went wrong with that request. Please try again.