THE ERROR:
Started GET "/users/invitation/new" for 127.0.0.1 at 2013-01-09 01:00:31 +0100
Processing by Devise::InvitationsController#new as HTML
User Load (451.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
Rendered users/invitations/new.html.erb within layouts/application (69.2ms)
Rendered layouts/_google_analytics.html.erb (0.4ms)
Rendered layouts/_navbar.html.erb (73.6ms)
Completed 500 Internal Server Error in 10785ms
ActionView::Template::Error (No route matches {:controller=>"devise/dashboards", :action=>"show"}):
23: </ul>
24: <ul class="nav pull-right" id="main-menu-right">
25: <% if user_signed_in? %>
26: <li><%= link_to raw("My Agenda"), {:controller => :dashboards, :action => :show}, :tabindex => "-1" %></li>
27: <li><%= link_to raw("My Services"), {:controller => :creative_services, :action => :index_my_services}, :tabindex => "-1" %></li>
28: <li id="fat-menu" class="dropdown">
29: <a href="#" id="dropUser" role="button" class="dropdown-toggle" data-toggle="dropdown">
app/views/layouts/_navbar.html.erb:26:in `_app_views_layouts__navbar_html_erb__952134567516339951_70121556350080'
app/views/layouts/application.html.erb:18:in `_app_views_layouts_application_html_erb___2663940439779075013_70121556359600'
On my Rails 3.1 project, I already use Devise.
I added devise_invitable gem in my Gemfile:
gem "devise", "~> 2.0.0"
gem 'devise_invitable', '~> 1.0.0'
Run these commands
rails generate devise_invitable:install
rails generate devise_invitable User
rake db:migrate
rails generate devise_invitable:views users
Set options in Devise.rb (Unlimited invitations
config.invitation_limit =
and start my server.
When I try to access /users/invitation/new
I am getting a routing error
Routing Error
No route matches {:controller=>"devise/dashboards", :action=>"show"}
In my User model:
devise :invitable, :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable, :invitable
My routes file:
devise_for :users, :controllers => { :registrations => 'registrations' }
How can I fix this routing issue?
workaround found here Routing error with devise {:controller=>"devise/static", :action=>"about"}
Changed my links:
26: <li><%= link_to raw("My Agenda"), {:controller => :dashboards, :action => :show}, :tabindex => "-1" %></li>
27: <li><%= link_to raw("My Services"), {:controller => :creative_services, :action => :index_my_services}, :tabindex => "-1" %></li>
to:
<li><%= link_to raw("My Agenda"), "/dashboards/show", :tabindex => "-1" %></li>
<li><%= link_to raw("My Services"), "/creative_services/index_my_services", :tabindex => "-1" %></li>
"and then all worked fine"
Related
I have upgraded my ruby version to ruby 2.6.6p146 and rails version to 4.2.8.
After updating the devise version is 4.6.0 and ransack version is 1.8.10.
Now on run time when I am trying to load my form for user login and it is using devise it is providing me this runtime error
ActionView::Template::Error (wrong number of arguments (given 3, expected 2)):
I am not getting why it is happening and checked my syntax also, here is my form code
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<h3 class="form-title form-title-first"><i class="icon-lock"></i>Event Admin Account Login</h3>
<div class="form-group">
<label>Username or Email</label>
<%= f.text_field :login, :placeholder => "Username or Email", :class => "form-control" %>
</div>
<div class="form-group">
<label>Password</label>
<%= f.password_field :password, :placeholder => "Password", :class => "form-control" %>
</div>
<div class="form-group">
<div class="checkbox">
<label>
<% if devise_mapping.rememberable? -%>
<%= f.check_box :remember_me %> Remember me
<% end %>
</label>
</div>
</div>
<%= f.submit "Sign in", :class=> "btn orange btn-lg" %>
<% end %>
I have tried every version of devise and after that I am at the current version, also tried to degrade ransack version, but it didn't help
Here is the stack trace
Started GET "/auction_admin/sign_in" for 127.0.0.1 at 2020-05-02 10:55:11 +0530
Processing by AuctionAdmin::SessionsController#new as HTML
Rendered auction_admin/sessions/new.html.erb within layouts/home (1088.8ms)
Completed 500 Internal Server Error in 1207ms (ActiveRecord: 5.0ms)
ActionView::Template::Error (wrong number of arguments (given 3, expected 2)):
11: <%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
app/views/auction_admin/sessions/new.html.erb:11:in `_app_views_auction_admin_sessions_new_html_erb___4037676396427670794_37299260'
app/controllers/auction_admin/sessions_controller.rb:14:in `new'
config/initializers/assets_silencer.rb:7:in `call_with_quiet_assets'
Rendered /home/rails/.rvm/gems/ruby-2.6.6#24f-new-ruby-2.6.6/gems/actionpack-4.2.8/lib/action_dispatch/middleware/templates/rescues/_source.erb (17.4ms)
Rendered /home/rails/.rvm/gems/ruby-2.6.6#24f-new-ruby-2.6.6/gems/actionpack-4.2.8/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.4ms)
Rendered /home/rails/.rvm/gems/ruby-2.6.6#24f-new-ruby-2.6.6/gems/actionpack-4.2.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (3.9ms)
Rendered /home/rails/.rvm/gems/ruby-2.6.6#24f-new-ruby-2.6.6/gems/actionpack-4.2.8/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (39.8ms)
I am making my website multilanguage using this railscast
But at the very beginning I get an error:
I18n::InvalidLocaleData in Users#index
Showing .../app/views/users/index.html.erb where line #1 raised:
can not load translations from .../config/locales/en.yml, expected it to return a hash, but does not
index.html.erb:
<% provide(:title, t('users.index.title.site_title')) %>
<h1><%= t 'users.index.title.head' %></h1>
<%= form_tag users_path, :method => 'get' do %>
<%= hidden_field_tag :direction, params[:direction] %>
<%= hidden_field_tag :sort, params[:sort] %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag (t 'users.index.search_form.search'), :name => nil %>
</p>
<% end %>
config/locales/en.yml
en:
users:
index:
title:
site_title: "Users"
head: "Users"
search_form:
search: "Search"
Locale data should be indented two spaces, not four, so correct version is:
en:
users:
index:
title:
site_title: "Users"
head: "Users"
search_form:
search: "Search"
Also, check if you're using spaces or tabs, latter will cause troubles.
I'm having trouble creating a many to many model for my project.
Basically i have a Matches & Teams model.
Teams are created prior to the Matches.
Once the match is created then i would like to add teams to it.
Match can have many teams, Teams can have many matches.
I'm currently adding teams via nested_form and adding multiple teams at once.
When submitting the form, i get an error expecting the team to be in a relationship already with the match.
I can do this with a many to one relationship but it fails with many-to-many, was wondering if there was any way to do it without doing a custom route.
Below is the form, controllers are as per default values.
Form:
<%= nested_form_for(#match) do |f| %>
<% if #match.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#match.errors.count, "error") %> prohibited this match from being saved:</h2>
<ul>
<% #match.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :date %><br />
<%= f.date_select :date %>
</div>
<%= f.fields_for :teams, :html => { :class => 'form-vertical' } do |builder| %>
<%= builder.label "Team Name:" %>
<%= builder.autocomplete_field :name, autocomplete_team_name_teams_path, :update_elements => {:id => "##{form_tag_id(builder.object_name, :id)}" },:class => "input-small",:placeholder => "Search" %>
<%= builder.hidden_field :id %>
<% end %>
<%= f.link_to_add raw('<i class="icon-plus-sign"></i>'), :teams, :class => 'btn btn-small btn-primary' %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Using a join model, the has_many :through macro and the accepts_nested_attributes_for macro you can do something like the following.
class Match
has_many :competitions
has_many :teams, :through => :competitions
accepts_nested_attributes_for :teams
end
class Competition
belongs_to :match
belongs_to :team
end
class Team
has_many :competitions
has_many :matches, :through => :competitions
end
Just make sure your form is set up to send the following data structure as params when the request reaches the create or update controller.
params => {
:match => {
# ...
:teams_attributes => [
{ :name => 'Foo', :color => 'blue' },
{ :name => 'Bar', :color => 'green' },
# ...
]
}
}
I have an error in my rails app telling me that the index method is undefined.
I have created a such simple form just for inserting data using the (new method page) only
but it is not working now for some reason
class PeoplesController < ApplicationController
def index
end
def new
#people = People.new
end
def create
#people = People.new(params[:#people])
if #people.save
redirect_to new_people_path
end
end
end
# new.html.haml
<h2>Hello there!</h2>
<hr >
<%= form_for #people do |f| %>
FirstName:<%= f.text_field :first %><br />
LastName:<%= f.text_field :last %><br />
<%= f.submit %>
<% end %>
Here is the error code:
NoMethodError in Peoples#new
Showing /Users/kasim/Desktop/form/app/views/peoples/new.html.erb where line #3 raised:
undefined method `people_index_path' for #<#<Class:0x007fa33da58d58>:0x007fa34031c578>
Extracted source (around line #3):
1: <h2>Hello there!</h2>
2: <hr >
3: <%= form_for #people do |f| %>
4: FirstName:<%= f.text_field :first %><br />
5: LastName:<%= f.text_field :last %><br />
6: <%= f.submit %>
The documentation for form_for says that a form_for call is equivalent to this
<%= form_for #post, :as => :post, :url => post_path(#post), :method => :put, :html => { :class => "edit_post", :id => "edit_post_45" } do |f| %>
...
<% end %>
Notice that the url attribute is calling out to a named route. In your case it appears the named route is people_index_path. I'd run rake routes and make sure that the named route in question really exists.
I have defined a function called is_logged_in? in a user defined library stored in the /lib directory, however when I try to use it in one of my views (in this case a _menu.html.erb view) I get a "undefined method `is_logged_in?' for #" error. I had assumed that if the method was available within the /lib directory then it would be accessible through the application?
my login_system.rb file is as follows:
module LoginSystem
protected
def is_logged_in?
#logged_in_user = User.find(session[:user]) if session[:user]
end
def logged_in_user
return #logged_in_user if is_logged_in?
end
def logged_in_user=(user)
if !user.nil?
session[:user] = user.id
#logged_in_user = user
end
end
def self.included(base)
base.send :helper_method, :is_logged_in, :logged_in_user
end
end
and my _menu.html.erb file is as follows:
<ul>
<li><%= link_to 'Home', '/' %></li>
<li><%= link_to 'Edit Page', pages_path %></li>
<li><hr size = "1" width = "90%" aligh = "left" /></li>
<% if is_logged_in? %>
<li> Logged in as: <i><%= logged_in_user.username%> </i></li>
<li><%= link_to 'Logout',{:controller => 'account', :action => 'logout'}, :method => :post%> </li>
<% else %>
<li><%= link_to 'Signup', :controller => 'users', :action => 'new' %> </li>
<li><%= link_to 'Login', :controller => 'account', :action => 'login' %></li>
<% end %>
</ul>
Can anyone point where I've gone wrong?
Bernard
edit your ApplicationController:
class ApplicationController < ActionController::Base
include 'login_system'
end
You might also want to try devise.
If you don't have some seriously different needs for login/logout accounts then it is great!