This is probably a very simple question to answer. i am new to Rails and am having difficulty figuring out something that I am certain is trivial. I have a simple link_to "Show" which is remote and works great. However once i click a remote link and the content is displayed into/from my partial I cannot seem to update that content by clicking again on another link. My server logs are showing the correct calls being made so I believe there must be something wrong I am doing with the callback. Maybe this has something to do with my :locals assignment in my partial. to better understand here is my code...
application.js
$(function() {
$("#showreqs a").live("click", function() {
$.getScript(this.href);
return false;
});
});
_showreq.html.erb (very simple to prove concept)
<%= @project.name %>
show.js.erb
$("#showreq").replaceWith("<%= escape_javascript(render :partial => 'showreq', :locals => { :project => @project}) %>")
projects.html.erb (only section that matters)
<div id="showreqs">
<%= form_for(@project) do |f| %>
<%= render 'shared/error_messages' %>
<p>
Name: <%= f.text_field :name %>
Owner: <%= f.select :user_id, options_from_collection_for_select(@users, 'id', 'name'), :class => 'genForm_dropBox' %>
<%= f.submit "Create Project" %>
</p>
<% end %>
<ol>
<% @projects.each do |t| %>
<li>
<%= t.name %> - Owner: <%= t.user.name %> -
<%= link_to "Show", t, :action => "show", :remote => true %>
|
<%= link_to "delete", t, :method => :delete, :confirm => "You sure?", :title => "Delete" %>
</li>
<% end %>
</ol>
</div>
projectscontroller (very ugly and will clean)
class ProjectsController < ApplicationController
def index
@title = "Requirements"
@users = User.order("created_at").all
@project = Project.new
@projects = Project.all
end
def show
@users = User.order("created_at").all
@project = Project.find(params[:id])
@projects = Project.all
end
def create
@project = Project.new(params[:project])
if (defined?(@project_e)).nil?
@project_e = Project.new(params[:project])
end
if @project.save
flash[:success] = "Successfully created a Project."
redirect_to projects_path
else
flash[:error] = "You made some errors"
redirect_to projects_path
end
end
def update
@project = Project.find(params[:id])
if @user.update_attributes(params[:user])
flash[:success] = "Project updated."
redirect_to projects_path
else
flash[:error] = "You made some errors"
redirect_to projects_path
end
end
def destroy
Project.find(params[:id]).destroy
flash[:success] = "Project destroyed."
redirect_to projects_path
end
end
If you need any other code such as routes let me know but i assumed my routes and everything else is fine since this does works when "show" link is first clicked.