I'm having hard time getting rails_admin to work without devise.
I tried https://gist.github.com/Overbryd/1068094
as well removing all the devise related code from my user model and routes
However, I'm getting the following error:
ActionView::Template::Error (Could not find a valid mapping for # From here
6: - if _current_user
7: - if user_link = edit_user_link
8: %li= user_link
9: - if logout_path.present?
10: %li= link_to content_tag('span', t('admin.misc.log_out'), :class => 'label label-important'), logout_path, :method => Devise.sign_out_via
11: - if _current_user.respond_to?(:email) && _current_user.email.present?
devise (2.2.3) lib/devise/mapping.rb:42:in find_scope!'
/home/eugene/.bundler/ruby/1.9.1/rails_admin-75079da0906e/app/helpers/rails_admin/application_helper.rb:36:inlogout_path'
Assuming you have a route similar to this:
get "logout" => "sessions#destroy", as: "logout"
Then you can do this:
- if _current_user
- if user_link = edit_user_link
%li= user_link
%li= link_to content_tag('span', t('admin.misc.log_out'), class: 'label label-important'), '/logout'
That simply replaces the Devise nonsense with a link to your overall sessions destroy route. You can also delete the logout_path method in the Application Controller as well.
Related
When trying to use user authentication I get the following error: "NoMethodError in Viewer#show". And it addresses the error to <%= #page.body.html_safe%> in app/views/viewer/show.html.erb:1:in '_app_views_viewer_show_html_erb__685858346_34780128', which is only one line code by now.
But, when I call login page on browser address bar like: :3000/session/new, it comes Up. Which is not happening with :3000/session/destroy.
It seems that something related to the route is not working properly because, on the other hand, when I call a page on views/layouts/application.htm.erb like <li><%= link_to 'Home', {:controller => 'viewer', :action => 'show', :name => 'home'} %></li> it works, and if I switch to <li><%= link_to 'Home', view_page_path('home') %></li> it gives a similar error.
How can I solve that?
Your use of view_page_path('home') assumes that there is a named path view_page. Changing
get "/:name" => 'viewer#show'
to
get '/:name' => 'viewer#show', :as => :view_page
should fix that.
Secondly when using route helpers with named parameters you need to specify the name so Rails knows what parameters should be used. Change view_page_path('home') to view_page_path(:name => 'home').
And finally a NoMethodError for <%= #page.body.html_safe%> suggests to me that either #page or #page.body is nil.
I'm getting this error when requesting this route: direct_appointment_url(#appointment.uuid, :subdomain => #user.name)
direct_appointment_url(#appointment.uuid, :subdomain => #user.name)
TypeError: can't convert Array to String
from ...rvm/gems/ruby-1.9.3-p362#example/gems/actionpack-3.2.12/lib/action_dispatch/http/url.rb:55:in `match'
route is defined as: get "/appointment/:uuid" => "schedule#appointment", as: "direct_appointment"
The values of the two vars passed in to the route matcher are:
appointment.uuid => "a52aff80-5b83-0130-987f-0026080ebf68"
and
#user.name => "example"
More context:
ActionView::Template::Error (can't convert Array to String):
13: Message: <%= #appointment.client_message %>
14: <% end %>
15:
16: View online: <%= direct_appointment_url(#appointment.uuid, :subdomain => #user.name) %>
17:
18: To see your latest appointments, login at: <%= #login_url %>
19: Your username is: <%= #user.email %>
app/views/user_mailer/new_appointment_email.text.erb:16:in `_app_views_user_mailer_new_appointment_email_text_erb__686277782469675039_70200502266100'
app/mailers/user_mailer.rb:13:in `block in new_appointment_email'
app/mailers/user_mailer.rb:12:in `new_appointment_email'
app/controllers/appointments_controller.rb:43:in `block in create'
app/controllers/appointments_controller.rb:42:in `create'
Ah, so much for useful error messages!
looking at the source code for https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/url.rb at line 55, (although blank) the previous lines show the error that should have been raised:
if options[:host].blank? && options[:only_path].blank?
raise ArgumentError, 'Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true'
end
once I specified a host, it worked:
direct_appointment_url(#appointment.uuid, :subdomain => "hello", :host
=> "blah")
=> "http://hello.blah/appointment/6a5cc9a0-5b8f-0130-9883-0026080ebf68"
Protip
Don't provide an array of possible hosts to your config file:
config.action_mailer.default_url_options = { :host => ['lvh.me:3000', 'blah.dev'] }
I'm using jquery mobile in a rails 3.0 app. I am getting a routing error when attempting to delete an item from a user's list. The code and error message are as follows.
index.mobile.erb:
<% #items.each do |i| %>
...
<div data-role="button">
<%= link_to 'Delete', i, :confirm => 'Are you sure?', :method => :delete %>
</div>
<% end %>
routes file:
resources :items, :except => [:show]
rake routes:
DELETE /items/:id(.:format) {:action=>"destroy", :controller=>"items"}
error message:
Started GET "/items/2" for 127.0.0.1 at 2012-02-26 13:31:37 -0500
ActionController::RoutingError (No route matches "/items/2"):
What am I missing?
Thanks!
UPDATE - Firebug:
#http://localhost:3000/javascripts/jquery-1.6.1.js?1310343332:641 #http://localhost:3000/javascripts/jquery.mobile-1.0.1.js?1329380575:2737 #http://localhost:3000/javascripts/jquery.mobile-1.0.1.js?1329380575:3030 #http://localhost:3000/javascripts/jquery.mobile-1.0.1.js?1329380575:3393 #http://localhost:3000/javascripts/jquery-1.6.1.js?1310343332:2926 #http://localhost:3000/javascripts/jquery-1.6.1.js?1310343332:2560
jquery...0343332 (line 641)
"NetworkError: 404 Not Found - http://localhost:3000/items/2"
Seems like the problem you're having is the same as mentioned # Rails' link_to method: GETing when it should DELETE.
Can you paste rest of the request parameters (chrome developer console or firebug)? Have to see if rails is trying to do magic to accomodate the HTTP delete verb.
In my config/routes.rb I have:
post "portal_plan_document/update"
rake routes confirms this:
$ rake routes
portal_plan_document_update POST /portal_plan_document/update(.:format) {:controller=>"portal_plan_document", :action=>"update"}
....
In my code I have:
<%= form_for #plan_doc,
:url => portal_plan_document_update_path,
:method => "POST", :remote => true do |f| %>
In my log file I see:
Started POST "/portal_plan_document/update" for 127.0.0.1 at 2011-03-31 18:04:37 -0400
ActionController::RoutingError (No route matches "/portal_plan_document/update"):
I am lost as what to do from here. Any help would be greatly appreciated!
I should state I am using Ruby 1.9.2 and Rails 3.0.5. Oh, I have restarted the server (WebBrick w/rails server) after updating routes.rb.
Jeremy
Figured it out! :)
if you have a non-empty object, rails assumes you want to update that object. i.e., use a 'PUT' instead of a 'POST'
to accomplish 'PUTs', rails will put a hidden input in the form, with "_method" = "put". so, it LOOKS like it's a POST, but rails is treating it as a PUT.
if you actually want to just update an object (what it looks like you're doing), a PUT is better, and you should just switch your routes over to PUT.
if (like I was), you're doing something that really requires a POST (i.e., it can't be sent more than once safely), you can write your form_for like this:
<%= form_for #plan_doc,
:url => portal_plan_document_update_path,
:html=>{:method => "POST"}, :remote => true do |f| %>
to confirm, look at the generated HTML source, and make sure the hidden "_method" field is not set to "put"
Try using that instead please :
:method => :post
If this does not still work, please lose the remote attribute and give it a try. Does it work without it ?
I had the same problem while upgrading a simple app from Rails 2 to Rails 3.
As you may guess I was updating all "remote_form_for(#item) (..)" helpers to "form_for :item remote => true (..)" syntax.
In my case this code from a items/_new.html.erb partial:
<%= form_for :item, :remote => true do |f| %>
<!--FIELDS-->
<% end %>
Gave me this error:
Started POST "/items/new" for 127.0.0.1 at Fri Aug 12 18:19:23
+0200 2011
ActionController::RoutingError (No route matches "/items/new")
As you can notice the method was a correct "POST", not a "PUT". The problem lied in the routing... I don't know why but when a remote POST method is sent by a partial, Rails routes the POST request to "/items/new" instead of "/items" route. Even if the purpose is to create a new "item" so the POST request should be correctly (and RESTfully) routed to "/items".
This code, with explicit action and controller, solved the problem:
<%= form_for :item, :remote => true, :url => { :controller => "items", :action => "create" } do |f| %>
<!--FIELDS-->
<% end %>
I have nested resources like this in my routes.rb - (my rake:routes gist)
namespace(:admin) do
resources :restaurants do
resources :menus
resources :menu_items
end
end
In the controller:
def new
#restaurant = Restaurant.find(params[:restaurant_id])
#menu_item = #restaurant.menu_items.build
end
Trying to create a new MenuItem (action #new), by the url: http://127.0.0.1:3001/admin/restaurants/1/menu_items/new I get the error:
NoMethodError in Admin/menu_items#new
Showing /home/fps/workspace3/peded/app/views/admin/menu_items/_form.html.erb where line #1 raised:
undefined method `admin_menu_items_path' for #<#<Class:0xb6582d78>:0xb6581f2c>
Extracted source (around line #1):
1: <%= form_for #menu_item do |f| %>
...
How do I make this form work? It was created out of a nifty:scaffold
UPDATE
I also tried this in the _form:
<%= form_for [:restaurant, #menu_item] do |f| %>
But ended with a similar error:
Showing /home/fps/workspace3/peded/app/views/admin/menu_items/_form.html.erb where line #1 raised:
undefined method `restaurant_admin_menu_items_path' for #<#<Class:0xb68162b0>:0xb6813dd0>
Extracted source (around line #1):
1: <%= form_for [:restaurant, #menu_item] do |f| %
Should I file a bug?
form_for([#restaurant, #menu_item])
I think the problem is in the form. This worked for me:
<%= form_for(#menu_items, :url => restaurant_menu_items_path(#menu_items.restaurant)) do |f| %>
I'm having the same issue. The only solution I have found is to pass a url to the form_for.
<% url = (action_name == "new" ? {:action=>"create", :controller=>"admin/menu_item"} : {:action=>"update", :controller=>"admin/menu_item"})%>
<%= form_for [#restaurant ,#menu_item], :url=>url do |f| %>
One additional note, you will not get params[:menu_item] back, instead you will see params[:admin_menu_item].
Hope that helps you out!
You can look up your routes by running on the command line.
rake routes
It looks like you're calling your routes incorrectly.
Array notation would be:
form_for([:admin, #restaurant, #menu_item])
And the named route for create:
admin_restaurant_menu_items_path(#restaurant)
Dealing with nested resources and namespaces is a Vietnam (pita).
Here is my nasty solution:
= form_for #admin_menu_item,
:url => (#admin_menu_item.try(:new_record?) ?
admin_restaurant_menu_items_path(#admin_restaurant) :
admin_menu_item_path(# admin_menu_item)) do |f|
...
I hope you can help.
The only solution that worked for me correctly (for both new and edit resource) was:
form_for #menu_item, :url => url_for([:admin, #restaurant, #menu_item])
I'm using Rails 5 (not that I imagine it matters) and this worked for me:
= simple_form_for [:admin, #restaurant, #menu_item] do |f|
The fact that it's simple_form_for rather than form_for probably doesn't matter either.
Funnily enough, I'm building an app with the same exact resource names.