Ruby on Rails
Monday, April 28, 2014
On Sunday, April 27, 2014 5:12:41 PM UTC-4, Ruby-Forum.com User wrote:
Thanks for looking at it. There goes the home controller bellow. And yes
I am using gem 'jquery-rails'. What is funny is that in my development
environment locally it is working. This error is from an passenger/nginx
installation.
Rod
class HomeController < ApplicationController
layout 'home'
def index
#sleep 1.5
#@shops = Shop.order("name").page(params[:page])
@shops = Shop.order('created_at desc').paginate(:per_page => 2,
:page => params[:page])
#User.paginate(:page => params[:page])
#query = Product.joins(:category)
query = Shop.joins(:product_options).where("product_id=1")
sql = query.to_sql
sql = "SELECT * from products"
r = ActiveRecord::Base.connection.execute(sql)
@query = r = r
zip= params[:zip]
@foundZip=false
if (!zip.nil? && !zip.blank?)
zip = zip.gsub('.','')
gc = GeoCity.find_by_ZIP(zip)
end
if (!gc.nil? && zip!=nil && !zip.blank?) # found zip
@foundZip=true
end
if request.xhr?
respond_to do |format|
format.html
format.js {render 'index' }
end
end
end
end
mike2r wrote in post #1144230:
> On Friday, April 25, 2014 11:22:23 PM UTC-4, Ruby-Forum.com User wrote:
>> net::ERR_BLOCKED_BY_CLIENT rev.js:4
>> at Function.target.(anonymous function)
>> event.preventDefault() instead. jquery.js:75
>> //
>> //= require jquery_ujs
>>
>>
>> # Specifies the header that your server uses for sending files
>>
>> server
>> # config.threadsafe!
>> # with SQLite, MySQL, and PostgreSQL)
>> <%= csrf_meta_tags %>
>> <html>
>>
>
src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/ "></script>jquery-ui.min.js
>> <!-- IE6 "fix" for the close png image -->
>> <ul class="sub-menu">
>> <% end %>
>> </li>
>> </html>
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>
> need to see the controller code. Basically, it's executing
> home.html.erb
> as a layout (it's not using the application.html.erb). Because of this,
> the following statement is missed:
>
> <%= javascript_include_tag 'application' %>
>
> I may have a better idea of exactly what's happening when I see the
> controller code. I'm also assuming that you have gem 'jquery-rails' in
> your Gemfile.
>
> Also, I would recommend you read the following guide as you aren't
> properly
> using layouts and templates:
>
> http://edgeguides.rubyonrails.org/layouts_and_rendering.html
--
Posted via http://www.ruby-forum.com/.
The statement causing the problem is:
layout 'home'
Rails uses layouts and templates in its view rendering system (plus other things, but let's start with that). The default layout is application.html.erb. With the above statement, you've overridden the default. I'm assuming that you were having issues because the default template for this action would be index.html.erb and you wanted it to be home.html.erb. You would accomplish that by 1) get rid of the layout statement and 2) insert the following statement at the end of the index action:
render template: 'home'
You will have some other issues when you do this. The layout is intended to be the overall framework and, at a minimum, includes the following:
<!DOCTYPE html>
<html>
.
.
</html>
The contents of the template (home.html.erb) will be inserted where you see the word yield in the application layout. In your case, you've defined the doctype and html tag in both the application layout and the template which will result in the html tag being defined twice which is invalid html. Again, I refer you to the guide linked above.
You're going to have a few other issues. You are separately loading the jquery and jquery-ui files from google. Once you have this working correctly, that will result in those files being loaded twice and potentially two different versions: the rails version and the version you're loading from google.
I also encourage you to go through a good tutorial such as railstutorial.org. You seem to have a pretty good foundation in ruby, so I don't think it would take you long to go through the tutorial. You are doing a lot of things in your controller that 1) you don't need to do if you work with Rails conventions and 2) some of them belong in a model.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4bd062a1-4e31-4ad3-9ee6-18e8e9502cbb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment