- Ajax functionality seems to fail when on adding a div tag to my .js.erb file
- $("#new_post").before('<div id ="new_post"><%= escape_javascript(flash.delete(:notice)) %></div>');<!--TO-DO the flash messages aren't yet enabled/working-->
- $("#latest_post").prepend("<%= @group_post.message %> by <%= Investor.find(@group_post.post_by).first_name %> <%= distance_of_time_in_words(@group_post.created_at,Time.now) %> ago <br/><br/><hr/>");
- $("#new_post")[0].reset();
- $("#latest_post").prepend("<%= @group_post.message %> by <%= Investor.find(@group_post.post_by).first_name %> <div class ="contentdispgrp"> <%= distance_of_time_in_words(@group_post.created_at,Time.now) %> ago </div><br/><br/><hr/>");
- <table>
- <tr>
- <%if @current_user.is_an_existing_member_of_group(@investor_group)%>
- <%form_for :group_post, @group_post, :url => {:action => :post_message, :id => params[:id]},:html => {:multipart => 'true', :id => 'new_post'} do |f| -%>
- Start Discussion:<br><%=f.text_field :message%>
- <!--<%=f.file_field :photo%> -->
- <%=submit_tag "Post"%></p>
- <%end%>
- <div id = "latest_post"> </div>
- <%for a in @group_all_posts %>
- <%= a.message %> by <%= Investor.find(a.post_by).first_name %> <div class ="contentdispgrp" id="style_chck"> <%= distance_of_time_in_words(a.created_at,Time.now) %> ago </div><br/><br/> <hr/>
- <%end%>
- </tr>
- <%end%>
- </table>
- def post_message
- @investor_group = InvestorGroup.find(params[:id])
- unless @current_user.is_an_existing_member_of_group(@investor_group)
- flash[:notice] = "Please join this group to participate in discussions"
- redirect_to :action => :show, :id => @investor_group and return # try to find out what exactly does this command do with return stmnt
- else
- @group_post = GroupPost.new(params[:group_post])
- end
- #@group_post = GroupPost.new(params[:group_post])
- investor_id = session['investor_id']
- @group_post.investor_group_id = @investor_group.id
- @group_post.post_by = investor_id
- if @group_post.save
- flash[:notice] = 'Post was successfully created.'
- # redirect_to :action => :show, :id => params[:id] - removed after trying to implement ajax via jquery
- else
- flash[:notice] = 'Post was not successfully created.'
- end
- respond_to do |format|
- format.html {redirect_to :action => "show", :id => params[:id]}
- format.js
- end
- end
- jQuery.ajaxSetup({
- 'beforeSend' : function(xhr) {
- xhr.setRequestHeader("Accept","text/javascript")
- }
- })
- $(document).ready(function(){
- $("#new_post").submit(function(){
- $.post($(this).attr("action"),$(this).serialize(),null,"script");
- return false;
- })
- })
- form_for :group_post, @group_post, :remote=>true ...
- format.js do
- puts "I am here"
- end