Issues implementing jquery-form plugin for displaying image via an ajax call in my rails poc

Hello all,

I am trying to implement a POC wherein I can post a message + image and
get the same working via AJAX to display them both for each new entry
without the page reloading.

I am using a config of Ruby 1.8.7 and Rails 2.0.2 for project specific
purposes… I am also using a pretty old paperclip commit from github for
this…I had to suit my proj config requirements mentioned previously…
Going forward, once I am able to successfully implement the POC I would
integrate the same in my Rails app.

I am currently facing some issues wherein I guess my project app is some
how not able to detect the jquery.form.js file… The exact error I am
getting is something like this from my log:-

ActionController::RoutingError (No route matches

“/javascripts/jquery.form” with {:method=>:get}):
recognize_path' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/routing.rb:1424:inrecognize’
handle_request' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:indispatch’
dispatch_cgi' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:indispatch’
process' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:74:insynchronize’
process' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:159:inprocess_client’
each' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:158:inprocess_client’
run' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:285:ininitialize’
new' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:285:inrun’
initialize' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:268:innew’
run' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:282:inrun’
each' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:inrun’
run' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/command.rb:212:inrun’
load' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:inload’
new_constants_in' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:inload’
gem_original_require' /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire’
require' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:innew_constants_in’
require' /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/commands/server.rb:39 /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:ingem_original_require’

I in a way am aware that I need to add my javascripts(jquery.js and
jquery-form.js) in my layout file as also mentioned in one of the
Railscasts by Ryan B…

I have done the same/similar in my app/views/layouts/posts.html.erb.
Basically it is said that we need to make changes in your
application.html.erb as per the Rails cast… but I don’t have any such
thing… Do I need to have one…?( I am sorry please bear with my being a
novice to Rails, this way).

My posts.html.erb file looks like this:-

<%= yield  %>
<%= javascript_include_tag 'jquery' ,'group' %>
<%= javascript_include_tag 'jquery.form','group' %>

I just had one doubt here… am I supposed to make use of yield… or it
should be removed…? Kindly direct me in case I am not using the right
syntax for adding jquery.form to my project app.

I also was able to find in more detail… some errors using firebug that
comes along with Mozilla… I am not fully adept in using firebug to deal
with these issues/debug their root cause yet…I also understand that I
would also need good knowledge on other things to fix this…

The current errors I am facing using firebug look something like this:-

jQuery is not defined
group.js?1306319739()group....6319739 (line 1)
[Break on this error] jQuery.ajaxSetup({
group....6319739 (line 1)
Ajax is not defined
(?)(Object { name="e"})group....6319739 (line 43)
handle(Object { name="a"})jquery...6302351 (line 63)
add()jquery...6302351 (line 57)
[Break on this error] dataType: 'script'
group....6319739 (line 43)
$(this).ajaxSubmit is not a function
[Break on this error] dataType: 'script'

My group.js file in public/javascripts is like this:-

‘beforeSend’ : function(xhr) {

$(’#post_msg input’).val(’’);

$(document).ready(function() {
$(’#uploadForm’).bind(‘submit’, function(e) {
//target: ‘#output
dataType: ‘script’

I tried doing some research/homework on some work arounds by referring
to :-

This in a way atleast helped me make sure , I don’t repeat this
mistakes… in my case…

I would like to mention how I am currently making things working for me
via html rendering:-

I have the home page from where i have a link to a “new post” which
directs me to a partial of my “new” method.
Once there onclick I get fields to enter every time:- a new message +
image… onsubmit a call is made to my create method which takes the
message and image as params, saves it and redirects to the partial
displaying the latest post made with the image that is uploaded if any…
I once again can then like in a loop post new image+message and redirect
to this after getting it saved in my create method.

To best explain this , I would like to add the code for my create
method, the _common.html.erb parital that I am rendering and finally the
create.js.erb which I want to get working for me… provided I am able to
fix my current issues…

create method:-

  def create
    @post =[:post])

    respond_to do |format|
      if @post.message
        flash[:notice] = 'Post was successfully created.'
        @posts = Post.find(:all, :order=>'created_at DESC')
     #   render :partial => 'new', :object => @posts
     #   format.html { redirect_to(@post) }
        format.html { render :action => 'new', :object => @posts }
        format.js { render :content_type => Mime::HTML.to_s }
        #{ render :partial => 'new', :object => 'posts'} # :text =>,
#format.xml { render :xml => @post, :status => :created,
:location => @post }
format.html { render :action => “new” }
format.xml { render :xml => @post.errors, :status =>
:unprocessable_entity }

My _common.html.erb file looks like this:-

<%= javascript_include_tag 'jquery.form', 'group' %>

<% remote_form_for(:post, :url => { :controller => "posts", :action

=> :create }, :html => { :method => :post, :id => ‘uploadForm’,
:multipart => true }) do |f| %>


<%= f.text_field :message %>

<%= f.file_field :photo %>
    <%= f.submit "Create" %>
<% end %>

 <div id = "latest_post"></div>
 <% for post in @posts %>
    <%= image_tag %>
    <tr><td><%=h post.message %></td></tr>
  <br/>  <hr/>
<% end %>

My create.js.erb file looks like this:-

<%= javascript_include_tag 'jquery.form', 'group' %>

$("#latest_post").prepend("<br/> <%if

!@post.photo_file_name.to_s.empty? %>

<%= image_tag %>
<%end%> <%= @post.message %>

$('#post_msg input').val('');

I am working on it from my end…Trying to find a fix around this…

In the meantime… I would be really glad to get any
inputs/suggestions/directions on what I am doing wrong in order to
correct my bad… it would really help…

Thank you…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs