I'm having the opposite problem of other related posts here. I'm using a gem that renders a page that uses the application's layout. That layout works fine in the application otherwise. In that layout is a named path, login_logout_path, that causes an undefined local or method error.
Here is a snippet of the view code:
<%= link_to( ApplicationName + ' Home', root_path ) %> |
<%= link_to('Sign Off', login_logout_path ) %> :
<%= get_session_login.iname %>
root_path works fine, logon_logout_path fails.
On complication might be that the layout above and the logon_logout_path is supplied by another gem that contains common code/layouts for the set of web sites.
Short Answer, change
login_logout_path
with:
main_app.login_logout_path
and add main_app to all your routes in the application.html.erb that go to your main app
Long answer:
The problem is that engines can have routes with the same name as a route in your main app and work without crashing, if you want to use a route of your main app inside your engine you have to specify it putting
main_app.
Before the route, and if you want to use a route of your engine in your main app you have to specify it with
engineName.example_path
The root_path works because your engine has defined a root_path, and it's send you to the root path of the engine, not the one in your app, you can fix it with adding main_app before it too.
Related
I have used multi step sign up form using jQuery.stepy.js Also I have added google ReCAPTCHA using 'gem "recaptcha"'. When I am placing
<%= recaptcha_tags %>
inside wizard form it is throwing JavaScript error like this:
Uncaught Error: ReCAPTCHA placeholder element must be empty
I have searched for the reason behind this error and found that this error occurs if the google recaptcha library is loading twice.
Is this happening because of jQuery.stepy.js ? How can I resolve this error?
This error occurs when recaptcha/api.js file gets loaded multiple times.
In your case you have used <%= recaptcha_tag %>, this tag inject api.js by default everytime it renders. Just check you haven't added the library file explicitly or using multiple recaptcha tags (each one will inject library script).
You can set :script param to false, by passing argument to method:
<%= recaptcha_tag :script => false %>
I have a rails application which is api only i am using gem rails-api. Now I am trying to create admin panel on it because we realised later that we do need an admin panel. But i think rails-api doesnt have good support for views.
When I try to submit forms it says undefined method protect_against_forgery? maybe because it doesnt supports <%= csrf_meta_tags %>
I tried to define manually this method in my controller but no luck.
def protect_against_forgery?
true
end
How can i submit the forms without getting this error.
in your api controller put following line.
skip_before_filter :verify_authenticity_token
or try with
def protect_against_forgery?
false
end
this may be help you.
According to rails-api, try to set config.api_only = false to config/application.rb file
Or, since protect_from_forgery is a method that belongs to ActionController, try to add require "action_controller/railtie" to application.rb
In my app.rb:
route '/' is routed properly, I can see all the categories on the page (so my app does have all the necessary information in TechBomagCategory table).
get '/' do
#categories = Category.all
erb :categories
end
And then
Category.all.each do |category|
get '/' + category.title do
erb :products
end
end
doesn't create necessary routes. When I go to any '/' + category.title page, 404 page occurs.
Notice that on my local machine everything works as expected, all the pages are rendered perfectly fine.
What went wrong, how should I fix it?
It figures simple
heroku restart
helps. I guess that route was nonfunctional because it was created when my categories table wasn't yet seeded.
I've been plowing through the chapters at railstutorial.org and been using Rails 3.1.3 because I'm crazy and/or wanted a challenge. I managed to figure out most version problems easily but this one stumped me for a while.
In 10.4.2, Michael Hartl uses the following code to delete users:
<%= link_to "delete", user, :method => :delete, :confirm => "You sure?",
:title => "Delete #{user.name}" %>
It doesn't work properly if you test it in the browser (chrome) and instead sends you to that user page.
It is supposed to work if you include this:
<%= javascript_include_tag :defaults %>
but it fails with Rails 3.1 (it should work for Rails 3.0 though, or so I hear).
So for all of you pulling out your hair for using Rails 3.1, here's the solution.
<%= javascript_include_tag "application" %>
Using "application" instead of :defaults solves this problem, delete and confirm should work, now get back to coding!
Special thanks to George Shaw for this answer over on https://stackoverflow.com/a/8350158/1127011 .
And it case you were wondering, title is for mouseover only.
The a HTML tag will always fire the GET method. Rails uses the Javascript driver to replace the HTTP verb. The link_to method will fallback any method (post, put and delete) to get (corresponding to the show action) when :
Javascript has been disabled by the user
for some reason, Rails unobtrusive javascript driver is not handling the link properly
See http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html
I suspect the second reason to be the issue. Make sure the jquery.js, application.js, jquery_ujs.js file are included.
Instead of link_to, you could try to use button_to which creates a form allowing put, post and delete methods without Javascript enabled.
In my rails (v2.3.8) app I have a static resource file which I've put at /public/myfile.kml No need for any special routes.rb setting right?
It serves up just fine at http://localhost:3000/myfile.kml
When I deploy (to passenger) it appears at http://myserver/myappname/myfile.kml
All is well so far...
I have a view (an erb file) which spews out javascript which needs to reference this file. The output needs to be '/myfile.kml' on localhost, and '/myappname/myfile.kml' in production, or maybe the full URLs as above, or maybe a relative url involving a bit of '../../../' (awkward with RESTful URLs).
Should I be able to do something like <%=url_for 'myfile.kml'%> ?
or '<%=ROOT_URL%>/myfile.kml'
I know there's an insanely easy answer to this question, but honestly I've had no luck finding it. Quite a few people talking about 'root_url' but what is that? A variable I can reference in a view? It's undefined.
I'm not sure about Rails 2.3.8, but in Rails 3 this value defaults to false.
edit config/environments/production.rb and set:
config.serve_static_assets = true
Also, here's a blog post that shows a helper for linking to a static resource (favicon)
http://ilconnettivo.wordpress.com/2008/07/28/favicon-on-rails/
'<%= ENV["RAILS_RELATIVE_URL_ROOT"] %>/myfile.kml'
<%= RAILS_ROOT + "/public/myfile.kml" %>
Inspection of rake routes reveals the helper root_path for use in views. For example <%= root_path + 'myfile.kml' %> By default will map to files under public/ in a rails application.
The latest (>2.3.6) is Rails.root, see:
http://joneslee85.wordpress.com/2010/05/27/the-dilemma-of-rails-root-vs-rails_root-complex/
Why not just replicate your production environment locally? A webserver is not very resource hungry and it can help resolve some ecosystem configuration issues like you're seeing here.