denver
(denver)
December 3, 2008, 11:00am
1
Hi Guys,
I am using attatchment_fu to adding images to my rails app, and have
the following
<%= article_image_for(@article ) %>
which displays the image for my article.. however i just want a text
link to the image instead of the image itself...
can this be done with a link_to? or an <a href=@article.image ...??
i know this is probably a simple thing to do!! cheers..!!
Here is my code.................
Is it not as simple as changing the above to
link_to 'click me', article_img
?
Fred
11175
(-- --)
December 4, 2008, 1:14pm
3
Frederick Cheung wrote:
def article_image_for(article)
� � � � if article.article_image
� � � � � � article_img = article.article_image.public_filename
� � � � � � link_to image_tag(article_img),
article.article_image.public_filename
Is it not as simple as changing the above to
link_to 'click me', article_img
?
Fred
i see what you mean...
i have made changes but now get the error.......
Showing admin/articles/edit.html.erb where line #12 raised:
undefined method `stringify_keys' for
"/article_images/0000/0047/Photo_59.jpg":String
Extracted source (around line #12 ):
9:
10: <% end %>
11: <% if(@article.article_image ) %>
12: <%= article_image_for(@article ) %>
13:
14:
15:
Frederick Cheung wrote:
def article_image_for(article)
� � � � if article.article_image
� � � � � � article_img =
article.article_image.public_filename
� � � � � � link_to image_tag(article_img),
article.article_image.public_filename
Is it not as simple as changing the above to
link_to 'click me', article_img
?
Fred
i see what you mean...
i have made changes but now get the error.......
Showing admin/articles/edit.html.erb where line #12 raised:
undefined method `stringify_keys' for
"/article_images/0000/0047/Photo_59.jpg":String
Extracted source (around line #12 ):
What's the rest of that stack trace?
Fred
11175
(-- --)
December 4, 2008, 1:36pm
5
Frederick Cheung wrote:
i have made changes but now get the error.......
Showing admin/articles/edit.html.erb where line #12 raised:
undefined method `stringify_keys' for
"/article_images/0000/0047/Photo_59.jpg":String
Extracted source (around line #12 ):
What's the rest of that stack trace?
Fred
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/url_helper.rb:201:in
`link_to'
app/helpers/admin/articles_helper.rb:6:in `article_image_for'
app/views/admin/articles/_show.html.erb:7:in
`_run_erb_47app47views47admin47articles47_show46html46erb'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/base.rb:342:in
`send'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/base.rb:342:in
`execute'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template_handlers/compilable.rb:29:in
`send'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template_handlers/compilable.rb:29:in
`render'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/partial_template.rb:20:in
`render'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:26:in
`benchmark'
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/benchmark.rb:8:in
`realtime'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:26:in
`benchmark'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/partial_template.rb:19:in
`render'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template.rb:22:in
`render_template'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/partials.rb:110:in
`render_partial'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/base.rb:277:in
`render'
app/views/admin/articles/index.html.erb:26:in
`_run_erb_47app47views47admin47articles47index46html46erb'
vendor/plugins/paginating_find/lib/paging_enumerator.rb:45:in `each'
vendor/plugins/paginating_find/lib/paging_enumerator.rb:45:in `each'
app/views/admin/articles/index.html.erb:24:in
`_run_erb_47app47views47admin47articles47index46html46erb'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/base.rb:342:in
`send'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/base.rb:342:in
`execute'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template_handlers/compilable.rb:29:in
`send'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template_handlers/compilable.rb:29:in
`render'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template.rb:35:in
`render'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template.rb:22:in
`render_template'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/base.rb:248:in
`render_file'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1112:in
`render_for_file'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:869:in
`render_with_no_layout'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:884:in
`render_with_no_layout'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/layout.rb:251:in
`render_without_benchmark'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:51:in
`render'
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/benchmark.rb:8:in
`realtime'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:51:in
`render'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/mime_responds.rb:131:in
`send'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/mime_responds.rb:131:in
`custom'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/mime_responds.rb:160:in
`call'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/mime_responds.rb:160:in
`respond'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/mime_responds.rb:154:in
`each'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/mime_responds.rb:154:in
`respond'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/mime_responds.rb:107:in
`respond_to'
app/controllers/admin/articles_controller.rb:16:in `index'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1166:in
`send'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1166:in
`perform_action_without_filters'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:579:in
`call_filters'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:572:in
`perform_action_without_benchmark'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:68:in
`perform_action_without_rescue'
c:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:68:in
`perform_action_without_rescue'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/rescue.rb:201:in
`perform_action_without_caching'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/caching/sql_cache.rb:13:in
`perform_action'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in
`cache'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/query_cache.rb:8:in
`cache'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/caching/sql_cache.rb:12:in
`perform_action'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:529:in
`send'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:529:in
`process_without_filters'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:568:in
`process_without_session_management_support'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/session_management.rb:130:in
`process'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:389:in
`process'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:149:in
`handle_request'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:107:in
`dispatch'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:104:in
`synchronize'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:104:in
`dispatch'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:120:in
`dispatch_cgi'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:35:in
`dispatch'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:76:in
`process'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:74:in
`synchronize'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:74:in
`process'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:159:in
`process_client'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in
`each'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in
`process_client'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`initialize'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`new'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in
`initialize'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in
`new'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in
`run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:282:in
`run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:281:in
`each'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:281:in
`run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:128:in
`run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/command.rb:212:in
`run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:281
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in
`load'
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in
`load'
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in
`new_constants_in'
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in
`load'
c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/commands/servers/mongrel.rb:64
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in
`require'
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in
`new_constants_in'
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in
`require'
c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/commands/server.rb:39
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
script/server:3
Frederick Cheung wrote:
i have made changes but now get the error.......
Showing admin/articles/edit.html.erb where line #12 raised:
undefined method `stringify_keys' for
"/article_images/0000/0047/Photo_59.jpg":String
Extracted source (around line #12 ):
What's the rest of that stack trace?
Fred
looks like you're passing that string to link_to twice.
Fred
11175
(-- --)
December 4, 2008, 1:53pm
7
Frederick Cheung wrote:
"/article_images/0000/0047/Photo_59.jpg":String
Extracted source (around line #12 ):
What's the rest of that stack trace?
Fred
looks like you're passing that string to link_to twice.
Fred
ummm interesting...
module Admin::ArticlesHelper
def article_image_for(article)
if article.article_image
article_img = article.article_image.public_filename
# link_to image_tag(article_img),
article.article_image.public_filename
link_to 'click me', article_img,
article.article_image.public_filename
#else
#image_tag ("blank-image.png")
end
end
end
this is my adapted articles helper method...
Well you are.
Just
link_to 'click me', article_img
is quite enough.
Fred
11175
(-- --)
December 4, 2008, 2:37pm
9
Frederick Cheung wrote:
# link_to image_tag(article_img),
article.article_image.public_filename
link_to 'click me', article_img,
article.article_image.public_filename
Well you are.
Just
link_to 'click me', article_img
is quite enough.
Fred
OK I understand now.
As a quick secondary question, I was wondering why when I have a button
to delete the image from the database it works perfectly in the
edit.html.erb file, but when I move the button into the _form.html.erb
file so that it sits next to the other image related elements the
@article_image.id value is not passed accross... in fact I dont think it
even is picked up in the first place.
<%= button_to "Delete Image", { :action => "delete_article_image",
:article_image_id => @article_image.id } %>
def delete_article_image
@article_image = ArticleImage.find(params[:article_image_id])
@article_image.destroy
respond_to do |format|
format.html { redirect_to(admin_articles_url) }
format.xml { head :ok }
end
end
As is the code for the button works on the edit page (which holds the
partial _form) but sits outside the rest of the elements and looks
rediculous having a "delete image" button at the bottom of the page.
Probably because behind the scenes the button helper creates a form
and you can't nest forms
Fred
11175
(-- --)
December 4, 2008, 4:35pm
12
Dave Smith wrote:
booger.... is there a potential workaround?
Umm... don't use that helper? You can always construct the control
yourself.
Hi Dave,
Dave Smith wrote:
Frederick Cheung wrote:
As a quick secondary question, I was wondering why
when I have a button to delete the image from the
database it works perfectly in the edit.html.erb file, but
when I move the button into the _form.html.erb file so
that it sits next to the other image related elements <snip>
Probably because behind the scenes the button helper creates a form
and you can't nest forms
Fred
booger.... is there a potential workaround?
Several. Al's given you one. Here's two more..
1) Use your existing code, but separate structure from presentation. Fix
the structure by putting the button (i.e., a form with no input fields)
outside the form tags and use CSS to position it.
2) Modify your existing code to use link_to or a variation with images
instead of text
HTH,
Bill