473,385 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Search using coffee script ajax in rails?

Exequiel
288 256MB
Hello friends, How can i get the _searchoutput.html.haml in my views/projects/_searchoutput.html.haml, using the controller projects_controller.erb accessed by my coffee script ajax search code and output it into tbody#search_output in views/projects/index.html.haml for search output.?

My code in controllers/projects_controller.erb
Expand|Select|Wrap|Line Numbers
  1. class ProjectsController < ApplicationController
  2.   # GET /projects
  3.   # GET /projects.json
  4.   def index
  5.     @projects = Project.all
  6.  
  7.     if !user_signed_in?
  8.       redirect_to "/users/sign_in"
  9.     else
  10.       if params[:search]
  11.         @projects = Project.search(params[:search]).order("updated_at ASC").page (params[:page])
  12.         # whats the codes here?????
  13.       else
  14.         @projects = Project.order("updated_at ASC").page (params[:page])
  15.         # whats the codes here?????
  16.       end
  17.     end
  18.   end
  19. end
  20.  
heres my ajax. .
Expand|Select|Wrap|Line Numbers
  1. $("input#search").keyup ->
  2.     search = $(this).val()
  3.  
  4.     $.ajax
  5.       url: "/projects?search=" + search + ".json"
  6.       type: "GET"
  7.       success: (searchoutput) ->
  8.  
  9.         $("tbody#search_output").html searchoutput
  10.         console.log searchoutput
  11.  
  12.       error: (request, status, error) ->
  13.         console.log request.responseText
  14.  
Heres is the code in views/projects/_searchoutput.html.haml
Expand|Select|Wrap|Line Numbers
  1. = content_tag_for(:tr, @projects) do |project|
  2.   %td= project.title
  3.   %td= project.decription
  4.   %td.shrink
  5.     = project.addbyemail
  6.   %td.shrink2
  7.     = project.created_at.strftime("%m/%d/%Y")
  8.   %td.shrink
  9.     = link_to 'Show', project, :class => 'btn btn-mini'
  10.   %td.shrink
  11.     = link_to 'Edit', edit_project_path(project), :class => 'btn btn-primary btn-mini'
  12.   %td.shrink
  13.     = link_to 'Delete', project, :class => 'btn btn-danger deleterow btn-mini', remote: true
and here is my code in views/projects/index.html.haml
Expand|Select|Wrap|Line Numbers
  1. %span#msg
  2.   .alert-success.msgsuccess
  3.     %a.close.msgclose{:style => "color: rgb(0, 136, 204);"} ×
  4.     %strong.msgdisplay
  5.  
  6. %h2 List of Projects
  7. %br/
  8.  
  9. %div{align: "center", style: "width:100%;"}
  10.   = form_tag projects_path, :id => 'search_form', :method => 'get' do
  11.     %table.tblsearch
  12.       %tr
  13.         %td.shrink
  14.           = submit_tag "Search", :name => nil, :class => 'btn btn-info '
  15.         %td= text_field_tag :search, params[:search], autofocus: true, :id => "search"
  16.  
  17. %br/
  18. %table.table.table-bordered.table-striped.topmargin
  19.   %thead
  20.     %tr
  21.       %th Title
  22.       %th Description
  23.       %th Posted by
  24.       %th Date created
  25.       %th
  26.       %th
  27.       %th
  28.   %tbody#search_output
  29.     = render "projects/searchoutput"
  30.  
  31. %div.leftside.linkx
  32.   = link_to 'Add Project', new_project_path, :class => 'btn btn-primary '
  33. %div.leftside.paginator
  34.   = paginate @projects
Note: Please don't use a filename.js.erb
Thank you and advance. . . :)
Please help me here, ,
Attached Images
File Type: jpg 1.jpg (50.1 KB, 258 views)
Jun 21 '14 #1
1 6543
Exequiel
288 256MB
Nobody knows rails here . . . I made the solution already, ,
Jun 22 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: rajarao | last post by:
hi I want to remove the content embedded in <script> and </script> tags submitted via text box. My java script should remove the content embedded between <script> and </script> tag. my current...
0
by: EC | last post by:
There are times when I use the Search utility of windows explorer to find ASPX file(s) that contains a specific word. The Search utility however skips the <script ..> </script> block in the ASPX...
0
by: Johan | last post by:
Hi How do I preform a paged search using the Directory searcher in VB.NET? I'm getting the first 1000 entries in the AD when I'm doing a normal search using the Directory searcher, and then...
3
by: Srinu | last post by:
How do i hide status bar in firefox using java script only Plz help me iam new to this group.
6
by: abdullah1983 | last post by:
Hi Guys, I need some clarification regarding the problem with safari browser. Please find my code below. I'm setting the image src, mouseover and mouseout using javascript. The mouseover and...
8
by: dbaplusplus | last post by:
I worked on web development using java script many many years, so I am now a newbie to javascript. I have a single html page, which is generated dynamically using some programming language. Web...
1
by: adamprisa | last post by:
1. Go to http://webwag.com 2. On the left hand side upper corner there is an "Add new Content" button, Click on it. 3. Enter a URL(suppose www.yahoo.com) in New! Widget On DemandTM TextBox and...
6
by: subhash9 | last post by:
Is it possible to write client side validations with out using javascript or ajax.
1
by: Damodhar | last post by:
How Can i Call php methods using java script?????
1
paulrajj
by: paulrajj | last post by:
How To Autorefresh div Every Two Minutes using php and ajax thanks in advance
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.