Hello all,
I am trying to render via javascript a post and an image in my rails
app. My app has the config of Ruby 1.8.7 and Rails 2.0.2 .
With great difficulty I have found a suitable version of paperclip(
) to meet the above config requirements.
Earlier before integrating image upload feature in my app for each post,
post message where being rendered via javascript using AJAX with Jquery
1.4 . This stopped working when I had try to implement uploading images
in my app using paperclip… I request you to please look into this for
details of the same:-
.
From this experience I have been able to in a way infer I need to find
an appropriate paperclip version suiting my requirements… unless…
they could be other ways to deal with this situation… If so… It would
be great if you could enlighten me on the same…
Going forward I have the following options with me:-
-
Find a suitable paperclip plugin which would have support for AJAX
using Jquery. (I am really not too sure on how I would be doing this…) -
Try using scriptaculous and/or prototype( I am unsure on whether I
need to use either or both of them ). The concern with this is , I have
to implement this from the scratch and I have to figure out from scratch
how to go about the same and also the fact that Ajax using Jquery
already works for me with post and not with post + Image.
I would like to add some details(code, other points) wrt option 1 wrt
the problem I am currently facing:-
I have used option 1 with the help of the Railscast by Ryan
Bates(#136 jQuery - RailsCasts).
I have made appropriate modifications referring to the same…
The file that I am trying to render via JS is post_message.js.erb looks
like this…
<!--$("#new_post").before('<div id ="new_post"><%=
escape_javascript(flash.delete(:notice)) %>‘); TO-DO the flash
messages aren’t yet enabled/working completely for now… →
$(“#latest_post”).prepend(“
<%= image_tag
@group_post.avatar.url(:thumb) %> <%= @group_post.message %> by <%=
Investor.find(@group_post.post_by).first_name %>
distance_of_time_in_words(@group_post.created_at,Time.now) %> ago
”);
$(“#latest_post”).append(“
<%for a in @group_all_posts %> <%=
image_tag a.avatar.url(:thumb) %> <%= a.message %> by <%=
Investor.find(a.post_by).first_name %>
distance_of_time_in_words(a.created_at,Time.now) %> ago
<%end%>”);
$(’#post_msg input’).val(‘’);
I am very much a novice with Jquery and hardly have around 3-4 months of
experience with RoR, I have one doubt over here if one could help me
clarify…If you have read
, you would observe by just removing the :id => 'new_post'
from within
the :html
symbol stopped the .js.erb from being rendered…
My doubt is I am pretty much unclear and lack knowledge on exactly what
role is the id
“new_post” playing… when I have actually commented the same… in my
post_message.js.erb… It might be that the id is used to uniquely
identlify the HTML partial that is being rendered… in which I
currently have the part of the code taking the parameters of the image
and the message along with it… Not too sure… Or is there any other
side to it …If so kindly widen my horizon on the same…
The part of the file(this is a partial) which otherwise gets rendered
via HTML has the following code in it:-
<%form_for :group_post, @group_post, :url => {:action =>
:post_message, :id => params[:id]},:html => {:multipart => true}, :id =>
‘new_post’ do |f| %>
Start Discussion:<%=f.text_field :message%>
<%= f.file_field :avatar %>
<%=f.submit “Post” %>
<%end%>
<div id = "latest_post"> </div>
<%for a in @group_all_posts %>
<%if !a.avatar_file_name.to_s.empty? %>
<br/><%= image_tag a.avatar.url(:thumb) %>
<%end%>
<br/><%= a.message %> <br/> by <%=
Investor.find(a.post_by).first_name %>
%> ago
My post_message method in my controller looks like this:-
def post_message
@group_post = GroupPost.new(params[:group_post])
#@group_comment = GroupComment.new(params[:group_comment])
@investor_group = InvestorGroup.find(params[:id])
@group_post.investor_group_id = @investor_group.id
investor_id = session['investor_id']
@group_post.post_by = investor_id
if !@group_post.message.blank?
@group_post.save
flash[:notice] = 'Post was successfully created.'
else
flash[:notice] = 'Post was not successfully created. Post
can't be blank’
end
# @group_comment.comment_by = investor_id
# @group_comment.group_post_id = :post_id
#
# if @group_comment.save
# flash[:notice] = ‘Comment was successfully created.’
# else
# flash[:notice] = ‘Comment was not successfully created.’
# end
@group_all_posts = GroupPost.find(:all, :conditions => [
‘investor_group_id = ?’, “#{@investor_group.id}” ], :order =>
‘created_at DESC’)
respond_to do |format|
format.html {redirect_to :action => "show", :id =>
params[:id]}
format.js
end
end
Kindly let me know if in case my providing any other information could
be of any help to answer my query…
Any suggestion on using either option 1 or 2 with where can I find
appropriate support for the same( for e.g. the version of the paperclip
that I could use in case I am go with option 1 or appropriate tutorials
I could make use of and what files I would need(like the jquery lib file
in case 1) in case of option 2) would be really of great use to me.
Kindly suggest me something that I can complete at the earliest without
too much effort (I have less than a day with me to get this working…)…
In the case if I would be actually able to get it working…
Thank you very much.