rails:2665
From: Shota Onishi <s-onishi@a...>
Date: Fri, 02 May 2008 09:07:56 +0900
Subject: [rails:2665] Re: route 指定と image_tag url_for( 〜 )で、アプリ名が2回繰り返される
大西と申します。
image_tagのところをこんなふうにしたらどうですか?
tag('img', :src => url_for(:action => 'file',
:id => atch.id,
:filename => atch.name),
:alt => h(atch.name)
)
roppongitoppogi@y... さんは書きました:
> ぱんと申します
>
> artonさんの「10日で〜」という本を元に、メールでアップロ
> ードしたファイルを、Web上に表示させるアプリを作っていま
> す。アップロードされた画像をMySQLに保存し、後述の設定で
> 呼び出すと;
>
> ▽「/app_name/memos/show/21」にて<gif画像>を表示しよう
> とした場合
> <img alt="20080426173214.jpg"
> src="/app_name/app_name/memos/file/7/20080426173214.jpg"
> />
>
> ※アプリ名が複数繰り返される
>
> ▽「/app_name/memos/show/22」にて<画像以外>にリンクを
> 貼ろうとした場合
> <a
> href="/app_name/memos/file/8/document.txt">document.txt</a>
>
> ※アプリ名は問題なく、1回だけ表示される
>
> という感じになってしまい、画像が表示されません。
> ※ローカルで、本の通りに作業していた際は問題なかったので
> すが、レンタルサーバ上でごりごりカスタマイズしてやりだし
> たら問題となりました。
>
>
> 何か、見直すべき点がありましたらご指摘下さい。よろしくお
> 願いします。
>
>
> ▼config/routes.rb
> # Install the default route as the lowest priority.
> map.connect ':controller/:action/:id/:filename.:fileext'
> map.connect ':controller/:action/:id/:filename'
> map.connect ':controller/:action/:id.:format'
> map.connect ':controller/:action/:id'
>
> ▼app/views/memos.rhtml
> <% for attachment in @memo.attachments %>
> <tr>
> <% for column in @memo.attachments.content_columns %>
> <td><%= format_attachment_column_value attachment,
> column.name %></td>
>
> <% end %>
> </tr>
> <% end %>
>
> ▼app/helpers/memos_helper.rb
> def format_attachment_column_value(atch, colname)
> if colname == 'content'
> if atch.content_type =~
> /image\/(x-|p)?(jpe?g|png|gif)/
> image_tag url_for(:action => 'file',
> :id => atch.id,
> :filename => atch.name),
> :alt => h(atch.name)
> else
> link_to h(atch.name), {:action => 'file',
> :id => atch.id,
> :filename => atch.name}
> end
> else
> h atch.send(colname)
> end
> end
>
>
> 以上
>
>
>
> --
> ML: rails@r...
> 使い方: http://QuickML.com/
>
>
--
ML: rails@r...
使い方: http://QuickML.com/
2662 2008-05-01 11:24 [roppongitoppogi@y...] route 指定と image_tag url_for( 〜 )で、アプリ名が2回繰り返される 2663 2008-05-01 13:07 ┣[someeda@g... ] 2664 2008-05-01 19:57 ┃┗[roppongitoppogi@y...] -> 2665 2008-05-02 02:07 ┗[s-onishi@a... ] 2666 2008-05-02 04:06 ┗[roppongitoppogi@y...] 2667 2008-05-02 07:02 ┗[s-onishi@a... ] 2668 2008-05-02 08:01 ┣[someeda@g... ] 2669 2008-05-02 11:13 ┗[roppongitoppogi@y...]