In my rails project I want to open a modal box (face box) via ajax. My code in the index.html.erb:
<%= link_to 'Anmelden', fb_login_path, :remote => true %>
This throws me the error:
Missing template facebox/fb_login, application/fb_login with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :arb, :coffee]}. Searched in: ...
That is right because my template is a js.erb-file. I read somewhere that I have to add in my controller:
FaceboxController:
def fb_login
respond_to do | format |
format.js
end
end
Doing this I am getting the error:
Started GET "/facebox/fb_login" for 127.0.0.1 at 2014-11-05 18:09:46 +0100
Processing by FaceboxController#fb_login as HTML
Completed 406 Not Acceptable in 0ms (ActiveRecord: 0.0ms)
This is weird because last week everything worked. In the meantime - as far as I remember - I didn't change a thing. But now I am getting this error.
I know this sounds weird but I hope that someone can help me.
Thanks!
Lars
EDIT
This ist my fb_login.js.erb-Code:
$.facebox('<%= escape_javascript(render :partial => 'devise/sessions/new') %>')
EDIT 2
Here is the output for rake routes
fb_login /facebox/fb_login(.:format) facebox#fb_login
and routes.rb:
match '/facebox/fb_login' => 'facebox#fb_login', :as => :fb_login
Perhaps that helps
Setting 'rails' in the gem file to '3.2.20' and running 'bundle update rails' finally worked for me.
Related
We are testing a customerx engine under spec/dummy. Index page of the engine customerx can be displayed without any error. Here is the link:
<li><%= link_to 'Customers', customerx.customer_status_categories_path %></li>
However there is routing error uninitialized constant CustomerStatusCategoriesController for new customer link as below:
<li><%= link_to 'New Customer', customerx.new_customer_status_category_path %></li>
The rake routes does show the right new customer route:
Routes for Customerx::Engine:
customer_status_categories_index GET /customer_status_categories/index(.:format) customer_status_categories#index
customer_status_categories_new GET /customer_status_categories/new(.:format) customer_status_categories#new
customer_status_categories_create GET /customer_status_categories/create(.:format) customer_status_categories#create
customer_status_categories_edit GET /customer_status_categories/edit(.:format) customer_status_categories#edit
customer_status_categories_update GET /customer_status_categories/update(.:format) customer_status_categories#update
customer_status_categories GET /customer_status_categories(.:format) customerx/customer_status_categories#index
POST /customer_status_categories(.:format) customerx/customer_status_categories#create
new_customer_status_category GET /customer_status_categories/new(.:format) customerx/customer_status_categories#new
edit_customer_status_category GET /customer_status_categories/:id/edit(.:format) customerx/customer_status_categories#edit
customer_status_category PUT /customer_status_categories/:id(.:format) customerx/customer_status_categories#update
In routes.rb for engine customerx, the resources is declared as:
resources :customer_status_categories, :only => [:index, :new, :create, :edit, :update]
There is no routing error with edit/index. The rspec cases for new/create all passes. The problem seems that the action for new is not found (the error is the same after deleting def of new and create).
What could be wrong in code causing the error? Thanks for help.
The problem was solved by commenting out get "customer_status_categories/new" in routes.rb for engine customerx:
Customerx::Engine.routes.draw do
get "customer_status_categories/index"
#get "customer_status_categories/new"
get "customer_status_categories/create"
get "customer_status_categories/edit"
get "customer_status_categories/update"
resources :customer_status_categories
root :to => 'customer_status_categories#index'
end
The get ...new in routes.rb was inserted by rails generate automatically when creating new controller. We don't know why this line causes uninitialized constant error (but not on others such as index and edit). Can Someone shed the light on the cause of the issue?
I created a scaffold without problems
$ rails generate scaffold New name:string title:string content:text
Rake command to run the migration (no problems as before, table correctly created)
$ rake db:migrate
Edit app/views/home/index.html.erb
<%= link_to 'My News', :controller => 'news' %>
I see the home and the link correctly in "http://localhost:3000"; clicking the link "My news" page "http://localhost:3000/news" is loaded without errors.
Now, clicking in the link "New New" generated by Rails, link's target localhost:3000/news/new (source "<a href ="/news/new">New New</ a>"), i read this error:
Routing Error
No route matches {:action=>"show", :controller=>"news", :format=>nil}
Try running rake routes for more information on available routes.
In "app/views/news/index.html.erb" the link souce is
<%= link_to 'New New', new_news_path %>
In routes.rb i read
MyApp::Application.routes.draw do
resources :news
get "home/index"
Rails 3.2.3
Ruby 1.9.3p125
MySQL 5.5
Windows 7 64 bit
Rakes routes:
news_index GET /news(.:format) news#index
POST /news(.:format) news#create
new_news GET /news/new(.:format) news#new
edit_news GET /news/:id/edit(.:format) news#edit
news GET /news/:id(.:format) news#show
PUT /news/:id(.:format) news#update
DELETE /news/:id(.:format) news#destroy
home_index GET /home/index(.:format) home#index
root / home#index
Thanks in advance and sorry for my English
you have to use news_index_path because news is not singular if rails can't make singular - prular distinguish they will add _index at the end :)
You have one news and many news and this is confusing.
Always try to use <name_of_resource>_path to generate urls :)
news_index GET /news(.:format) news#index
This says it implicit, you use 1 part news_index and add _path to get path for it.
You should have
<%= link_to 'My News', news_index_path %>
Hope that helps, cheers!
Our platform has been online for a while and working just fine. Our customers are able to download their invoices in PDF format just fine.
We've been working on a upgrades for a few month, and just today we noticed that "suddenly" non of our PDF generation with wicked_pdf and wkhtmltopdf no longer worked...
I have absolutely no idea why, I checked everything I could think of:
- routes
- initializers
- gems
- etc.
Everything seems to be fine, same as the actual only version.
We have not changed Rails or Ruby version. Everything is pretty much the same:
- Ruby 1.8.7 REE
- Rails 3.0.10
The error we are getting is:
Rendered groups/clients/proforma.pdf.haml (103.4ms)
Sent data toto.pdf (2.7ms)
Completed 500 Internal Server Error in 6892ms
NoMethodError (undefined method `virtual_path' for text template:ActionView::Template::Text):
app/controllers/groups/clients_controller.rb:980:in `proforma'
app/controllers/groups/clients_controller.rb:976:in `proforma'
lib/include/flash_session_cookie_middleware.rb:16:in `call'
lib/include/flash_session_cookie_middleware.rb:16:in `call'
The controller looks like:
def proforma
#request = WireRequest.where(:_id => params[:id], :status => :pending).first
respond_to do |format|
format.html {render :layout => false}
format.pdf do
unless #request.nil?"
render(:pdf => "PROFORMA_#{#request.invoice_num}", :layout => 'pdf')
end
end
end
end
Any ideas of what could be going wrong? I have no more ideas :(
I already had this kind of issue using the new relic rpm for developers.
I forked the gem here.
I followed a how to by CoverHound see
How to Create a Fan-gated Facebook Tab with Rails and JavaScript.
Everything went smooth up until step 3 under Serve the content for your FB App with a Rails application When previewing using my local server, I got an error. Typical rails security issue, simply solved by adding
protect_from_forgery :except => :index
to my FacebookController. From there I was golden, tested it on my live site and work swimmingly. Now to add the Gate!
Added the if statement to my facebook index.html.erb file
<% if user_likes_page? %>
<div class="fans_tickets"></div>
<% else %>
<div class="like_tickets"></div>
<% end %>
In the FacebookHelper I added the following to test for the like, and to parse the signed_request from Facebook
def user_likes_page?
fb_request = parse_signed_request
return fb_request['page']['liked'] if fb_request && fb_request['page']
end
def parse_signed_request
if params[:signed_request].present?
sig, payload = params[:signed_request].split('.')
payload += '=' * (4 - payload.length.modulo(4))
data = Base64.decode64(payload.tr('-_','+/'))
JSON.parse( data )
end
rescue Exception => e
Rails.logger.warn "!!! Error parsing signed_request"
Rails.logger.warn e.message
end
When tested on my localhost, It works great, if I haven't liked the page, I see the div with the info telling me to like the page for the contest info, when I have liked the page it shows me the info about the contests mentioned on the non-fan div. Great!
Post it to the Live server and I get an error page that shows up. In my Logs I see this...
2011-09-23 12:38:29 INFO -- Processing by FacebookController#index as HTML
2011-09-23 12:38:29 INFO -- Parameters: {"signed_request"=>"-IIMtqxxUICCyfCOxpsBMvApiaLgEZAkr1tQltvK_bI.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImlzc3VlZF9hdCI6MTMxNjgwMzEwNywicGFnZSI6eyJpZCI6IjEzNzg2NDQ2NjMxMDQwOSIsImxpa2VkIjp0cnVlLCJhZG1pbiI6dHJ1ZX0sInVzZXIiOnsiY291bnRyeSI6ImNhIiwibG9jYWxlIjoiZW5fVVMiLCJhZ2UiOnsibWluIjoyMX19fQ"}
2011-09-23 12:38:29 WARN -- !!! Error parsing signed_request
2011-09-23 12:38:29 WARN -- undefined method `encoding' for #<String:0x7f845221da58>
2011-09-23 12:38:29 INFO -- Rendered facebook/index.html.erb within /layouts/facebook (37.4ms)
2011-09-23 12:38:29 INFO -- Completed in 77ms
2011-09-23 12:38:29 FATAL --
ActionView::Template::Error (undefined method `[]' for true:TrueClass):
1: <% if user_likes_page? %>
2: <div class="fans_flames_tickets"></div>
3: <% else %>
4: <div class="like_flames_tickets"></div>
app/helpers/facebook_helper.rb:4:in `user_likes_page?'
app/views/facebook/index.html.erb:1:in `_app_views_facebook_index_html_erb___1213205873_70103145189880_0'
app/controllers/facebook_controller.rb:6:in `index'
I can't seem to figure out what would be causing this, the code doesn't look to be relying on anything from the actual server itself... Any help would be appreciated!
oh and I didn't continue on with the "How do I get the Facebook userID of the visitor viewing my fan page?" as I don't require it, its just for the like information.
UPDATE
Figured it out with debugging... should have been obvious. My Local host was implementing JSON with Guard running. With Guard only working in my development mode, JSON was installed on on development. Installed on Production and presto...
Feel kinda dumb for not having noticed this sooner! Thanks for all the help Dave & Keith
I'm pretty sure the undefined method 'encoding' for #<String... error has to do with running the app on ruby 1.8.7 vs. 1.9.2 or higher. i.e. it looks like your Live server is running 1.8.7 or possibly Ruby Enterprise Edition.
If you can, switch your live server to a ruby 1.9.2 version and see if that fixes it. Otherwise I'll dig in a little more this weekend.
Cheers!
-kw
I have a named route that tests properly in the console and shows the :url_title which should be included in params[], yet params[] is always empty.
The question is, why is params[] empty? My expectation is it should have params[:url_title].
I also removed this route and used the default resource and params[] is still empty.
I've been checking params by using logger.
My app is an upgrade from Rails 2.3.5 to Rails 3.0.3.
Here's a code summary of what's going on.
# this is my route
match 'papers/:url_title' => 'papers#show', :as => :permalinkpaper
# this is link_to and the generated url being called
<%= link_to paper.title, paper_path(paper.url_title) %>
http://localhost:3000/papers/great-passion
# which properly matches to this controller#action for papers#show
def show
#paper = Paper.where(:url_title => params[:url_title]).first()
PaperHistory.add( current_user, #paper.id )
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => #paper }
format.json { render :json => #paper }
format.mobile # { render :layout => false }
end
end
# which generals this error because the Paper looking returns noting because the params[:url_title] is nil
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
# the log stack trace
Started GET "/papers/great-passion" for 127.0.0.1 at Mon Jan 24 23:04:04 -0600 2011
Processing by PapersController#show as HTML
SQL (0.7ms) SHOW TABLES
SQL (0.5ms) SHOW TABLES
Paper Load (0.7ms) SELECT `papers`.* FROM `papers` WHERE (`papers`.`url_title` IS NULL) ORDER BY title LIMIT 1
Completed in 119ms
RuntimeError (Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id):
app/controllers/papers_controller.rb:43:in `show'
# I've validated the route in the console and it seems to know :url_title is the proper value
>> r = ActionController::Routing::Routes
>> r.recognize_path "/papers/great-passion"
=> {:action=>"show", :url_title=>"great-passion", :controller=>"papers"}
UPDATE: I have found that params[] are NOT empty when values are in the URL, such as when performing a search.
http://localhost:3000/papers?utf8=%E2%9C%93&keywords=passion
This successfully produces
Started GET "/papers?utf8=%E2%9C%93&keywords=passion" for 127.0.0.1 at Tue Jan 25 00:20:07 -0600 2011
Processing by PapersController#index as HTML
Parameters: {"utf8"=>"✓", "keywords"=>"passion"}
params: utf8✓keywordspassion
Thanks to all for the help. I was able to disassemble my app piece by piece and finally get params[] to show up.
The culprit was the open_id_authentication plugin.
I had some plugins in the vendors directory, so I removed them all and after hurdling a few resulting errors (b/c the plugins were now missing) everything worked. I systematically replaced plugins, and when I got to open_id_authentication found that the params[] again disappeared.
I had a different solution for this problem that I'll post here just in case somebody runs into the same issue. I was working on a password reset part of the site and tried various things such as putting the URL in manually, specifying the controller and action, using a bare (minimal) form and such, but all of it failed. The error given was the e-mail parameter was blank.
A look into the Exceptional logs showed that not just the e-mail parameter was blank, but even the UTF-8 check mark was missing. The only things in the params hash were the controller and action. Reloading the page also didn't turn up the usual spiel about re-submitting information.
It turns out the problem was in SSL. The page was trying to use SSL but didn't have permission and it was somehow silently killing the form. Hope that helps somebody.