I’ve got two localhost webservers running (webrick); one at port 3000 (server) and one at 3001 (webpage). But this is pointless because it seems to be broken on the server-side.
On the “server”, if I go to ‘http://localhost:3000/projects/5.js’, nothing loads. I get a white screen and ‘view page source’ is not even available as as options.
I’m guessing that document.write is the problem but I can’t troubleshoot it because nothing is loading. Is there a route that I need maybe? Is there something different that I need to do in my projects/show action?
####The website embedded code:
<iframe src="http://localhost:3000/projects/5.js"></iframe>
####projects_controller.rb
def widget
@project = Project.find(params[:id])
end
def show
@project = Project.find(params[:id])
respond_to do |format|
format.html { render :layout => 'application_project' }
format.json { render json: @project }
end
end
####projects/show.js.erb
document.write("<%= escape_javascript(content_tag(:iframe, '', :src => widget_project_url(@project))).html_safe %>");
####projects/widget.html.erb
<div id="project-embed-widget">
<h3><%= link_to @project.name, @project %></h3>
<% if @project.funding? %>
<h4>
<% if @project.backers.nil? %>
0
<% else %>
<%= @project.backers.count %>
<% end %>
BACKERS</h4>
<% @project.calc_goal_collected %>
<h4><%= number_to_currency(@project.goal_collected, :unit => "$") %></h4>
<h4>PLEDGED OF <%= number_to_currency(@project.goal, :unit => "$") %> GOAL</h4>
<h4><%= @project.time_to_go[:time] %>
<%= @project.time_to_go[:unit].upcase %> TO GO</h4>
<br />
<%= render "funding_message" %>
<br />
<% else %>
<%= @project.about %>
<% end %>
</div>
####routes.rb
resources :projects do
member do
get 'widget'
end
end
Well, one thing I noticed is that you’re calling
<iframe src="http://localhost:3000/projects/5.js"></iframe>but js isn’t one of your response formats in the controller. Addformat.jsto the respond_to block.