I have a user's dashboard page where there is a sidebar on the left side such as projects, blogs etc. I would like to be able to click on a link like "Projects" link and then in the main area, the view for projects (see the bullet list of projects) will be loaded without refreshing the page. I will do it with AJAX I am trying, but things are not working.
Here I think it's going to work. User Where And then, the Where And this is my Obviously, I am doing the wrong thing because it is not working. What am I doing wrong? Do I need to change some more code? I am at Rail 3.2.13, so under The problem is that your Therefore, to avoid duplicate code, here is what I do: In addition, you should not use show.html.erb
/ dash is configured for users # Show
config / routes.rb is as follows:
Match '/ Dash' = & gt; 'User # Show'
show operation is called in the
users_controller.rb controller: < Pre>
Def Show @ User = User.Fund (Params [: ID]) @ Projects = @ User Points. Format Format.html # renders show.html.erb format.js # renders show.js.erb End End
show.js.erb is executed . This is a line in my
show.js.erb file:
$ ('# ajax'). Html ("& lt;% = escape_javascript (render (: partial = & gt; project / index ')). Html_safe% & gt;");
show.html. ARB :
& lt; #Ajax div is to be modified in div id = "Ajax" & gt; & Lt;% = Render: Template = & gt; 'Project / Index'% & gt; & Lt; / Div & gt;
Apps / Ideas / Project / Index.html. RB takes in projects and gives a list, such as:
<% @ projects.each do | Project | & Gt%; & Lt; P & gt; & Lt;% = project.name% & gt; & Lt; / P & gt; & Lt;% end% & gt;
// = jquery and
// = jquery_ujs under
app / assets / javascripts / application.js Must Import Required jQuery and AJAX Functionality
Show.js.erb file is partly But you are giving it a file which is not partial, partial files start with underscore
_ .
# app / visual /projects/show.js.erb $ ('# Ajax '). Html ("& lt;% = escape_javascript (render: partial = & gt; 'index',: local = & gt; {: projects = & gt; @projects})% & gt;"); #app / ideas / project / index.html ARB & lt;% = Render: Partial = & gt; 'Index',: local = & gt; {: Projects = & gt; @ Project}%> #Applications/Project/ ** _ ** index.html.erb # Include code that you did earlier in index.html.erb # Do not forget to change projects @ projects; projects.each; Do Project | & Gt%; & Lt; P & gt; & Lt;% = project.name% & gt; & Lt; / P & gt; & Lt;% end% & gt;
matches in your own routes, because you will never need your routes too much, both GET and POST Should be accessible from the methods. Then try using
get instead of
mail .
No comments:
Post a Comment