w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Using current_user and other Devise Helpers in the rails console
Best thing would be to use pry gem. Once you install it, just add the line pry to your controller and you can access current_user. You cannot access current_user from console in any other way since it is session based.

Categories : Ruby On Rails

How to Fix Rails Code when Moving it From Controller to Helpers?
You could have them inside the model as a hash like this user.rb def User def self.language { 'English' => '1', 'French' => '2', .... } end end and in the controller obtain the hash into a variable and it will be accessible in both the html.erb and the js.erb users_controller.rb @language = User.language Then while building the form you can do it as <%= talent_field.select(:language, @language, {}, {:class => 'language-select'} %>

Categories : HTML

rails can custom helpers use other helpers? (image_tag, radio_button_tag etc?)
Example from one of my projects def apply_button(offer) ... a lot of code here ... link_to span.html_safe, offer_applications_path(offer), method: :post, remote: true, id: 'offer-apply-button' end

Categories : Ruby On Rails

Ruby on Rails Devise after_sign_in_path_for called on unrelated controller
Argh, silly mistake. Why is it after hours of struggling that when you post a question on Stack Overflow you figure it out after like 5 minutes?! I had copied and pasted my RegistrationsController into the WantsController file to save typing the controller code but forgot to make it inherit from ApplicationController rather than Devise::RegistrationsController. Lesson: Don't copy and paste!

Categories : Ruby On Rails

Rails: User does not respond to 'devise' method” when running “rails generate devise:install"
It looks like you have devise generator previously run unsuccessfully. Backtrace gives a clue that error happens within config/routes.rb line 2. I guess there is a following line of code, setting up devise routes devise_for :users But your users model doesn't have devise modules setup. There should be something like # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :timeoutable and :omniauthable devise :database_authenticatable, :rememberable, :trackable, :validatable If this line is present it means that devise is improperly installed. Also there is a chance that you have another class or module "User" within ActiveSupport::Dependencies autoloader paths and when devise_for :users line requires User class this class/module loaded fir

Categories : Ruby On Rails

Ruby on Rails: Custom Devise Registration Controller, Asking For Create Action
Your controller of registration inherits from the wrong class: DeviseController It is a base class for a registration and has no "create" method, and so does your custom Devise::RegistrationsController class (it has only edit and update methods) - it incurs the error. In order to create your own custom registration controller for users with fallback to the original devise methods, I suggest you do the following: 1. create "users" folder in controllers folder 2. create there registrations_controller.rb file, and define class there: Users::RegistrationsController < Devise::RegistrationsController and override any actions ("edit" and "update") 3. inform the "routes.rb" file about changes: devise_for :users, :controllers => { registrations: 'users/registrations' }

Categories : Ruby On Rails

How to make your own properties, eg. "devise :authenticable" in ruby / rails
Great part about open source stuff is you can just take a look and find out. I've removed some non-relevant lines (gems/devise-2.2.3/lib/devise/models.rb:83): def devise(*modules) devise_modules_hook! do include Devise::Models::Authenticatable selected_modules.each do |m| mod = Devise::Models.const_get(m.to_s.classify) if mod.const_defined?("ClassMethods") class_mod = mod.const_get("ClassMethods") extend class_mod if class_mod.respond_to?(:available_configs) available_configs = class_mod.available_configs available_configs.each do |config| next unless options.key?(config) send(:"#{config}=", options.delete(config)) end end end include mod end end end All dev

Categories : Ruby On Rails

Make help message appear below form field with Rails/devise/boostrap/simple_form
You should use CSS3 fade in/out flair. Try add this style : fieldset input:focus+.field-help { opacity:1; top: 0; max-height: 20px; margin-bottom:10px; } demo : http://jsfiddle.net/RVGPd/1/

Categories : CSS

Devise : No route matches {:controller=>"devise/about"}
Check your log files (log/development.log) for more information on the error - you are most likely coding a link on that page with an invalid route. Note that the error is about devise/about, not the users/sign_up that you're visiting.

Categories : Ruby On Rails

Error with Devise - Cannot run rails s or any devise commands
Maybe you can shifting to rails edge. gem 'rails', github: 'rails/rails' gem "devise", "~> 3.0.1" (https://github.com/rails/rails/issues/10559)

Categories : Ruby

Adding rails 3 form helpers to rails 2
My problem above was that i was not overriding the FormBuilder. Here is a solution for those who might need this in the future. Rather than just implementing the type="number" input type, i decided to make a generic helper for all new HTML5 inputs. I place this code in an overrides file which i include in application_helper.rb. # file 'rails_overrides.rb` ActionView::Helpers::InstanceTag.class_eval do def to_custom_field_tag(field_type, options = {}) options = options.stringify_keys to_input_field_tag(field_type, options) end end ActionView::Helpers::FormBuilder.class_eval do def custom_field(method, options = {}, html_options = {}) @template.custom_field(@object_name, method, objectify_options(options), html_options) end end # form.custom_fi

Categories : Ruby On Rails

Is it possible to include modules in rake task and make its methods available for the task in rails app?
require 'modules/module_name' include ModuleName namespace :rake_name do desc "description of rake task" task example_task: :environment do result = ModuleName::method_name() end #end task end This works for me. Since your Module is not in /lib you might have to edit how it is required. But it should work. Hope it helps.

Categories : Ruby On Rails

Rails devise let user sign in on one rails app by checking the users credentials on a second rails app
I think it can be solved via SSO Maybe it will be useful for you: http://blog.joshsoftware.com/2010/12/16/multiple-applications-with-devise-omniauth-and-single-sign-on/.

Categories : Ruby On Rails

Redirecting modules controller to one specific controller in HMVC codeigniter
If you have specified the complete site url, into redirect there is already the path without using base_url() try this: if(!$this->session->userdata('user_type')){ redirect('/users/login'); }

Categories : Codeigniter

Rails - how to make accessible one controller action for all pages?
I checked this question, Ruby Class#new - Why is `new` a private method? From the above link and a little bit of google I did, I found that, this link's ContactMessage class in the ActiveModel::Conversion, may have contradicted with your definition.

Categories : Ruby On Rails

CanCan: set abilities based on controller data or helpers
Ok, so I figured it out with a different approach. CanCan adds a current_ability method to ActionController::Base which instantiates a new Ability object and passes the current_user object to it. One can simply overwrite the current_ability method in an own controller, so I ended up doing this: class ApplicationController < ActionController::Base def current_ability @current_ability ||= Ability.new(current_user, Organization.find_by(id: cookies[:current_organization]) end end class Ability include CanCan::Ability def initialize(user, currently_selected_organization) if user.is_admin_for(currently_selected_organization # ... end end end This way it doesn't break the MVC pattern and I didn't end up including helper modules or hack anything.

Categories : Ruby On Rails

Block helpers in rails
Roughly: def needs_clearance(level, &block) if current_user.clearance >= level capture(&block) end end Block helpers generally look like the following, e.g., to wrap something in a div: def box(&block) "<div class='box'>" + capture(&block) + "</div>" end From: http://timelessrepo.com/block-helpers-in-rails3 I'd consider reading that, too, as it discusses an interesting consequence of block helpers.

Categories : Ruby On Rails

Rails helpers without @template.content_tag
You want to generate HTML from your helpers, I assume? You can simply generate strings using any method you want. If you call html_safe that will prevent the special characters from being escaped. def header_helper '<div class="header">This is a test</div>'.html_safe end And in the template <%= header_helper %> <p>This is the content of the section</p>

Categories : Ruby On Rails

Where rails store standard helpers?
Rails' form_tag is defined here: http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html However, that won't answer your question - the helpers that twitter-bootstrap-rails provides will be in the gem itself. See: https://github.com/seyhunak/twitter-bootstrap-rails/tree/master/app/helpers

Categories : Ruby On Rails

Make asp.net mvc validation work without helpers
While it is possible to perform unobtrusive validation in MVC without using helpers, it will be painfully for you as developer to do it manually without usage of mvc helpers. Saying strictly, it will kill your performance and make your code unreadable. Basically, unobtrusive validation consists of two parts: server side, via data-attributes to your model fields and MVC Helpers, which generate necessary markup, and client side library, jquery.validate.unobtrusive.js, which parses those markup to meaningful parts for jquery validate plugin. So, in general, you can manually write necessary markup, as long as validation js library will be loaded, validation will work. For example, field, which is subject of validation, must be marked with data-val='true' attribute. If you want to make your f

Categories : Asp Net Mvc

Uninitialized constant ActionView::Helpers::InstanceTag in Rails 4
After some research. I found that ActionView::Helpers::InstanceTag is transformed into module called ActiveModelInstanceTag ActionView::Helpers::ActiveModelInstanceTag

Categories : Ruby On Rails

Rails how to call helpers such as .humanize on an attribute of collection_select
With Rails 4 Just like this: <%= collection_select(:template, :template_id, @templates, :id, Proc.new {|v| v.name.humanize}) %> In the Proc block, v will be your models, iterated through a each loop. collection_select works with anything that inherit from Enumerable and have no limit in the content of the Proc. With Rails 3 You must do it your self, by preparing your data before passing it to collection_select # This will generate an Array of Arrays values = @templates.map{|t| [t.id, t.name.humanize]} # [ [record1.id, record1.name.humanize], [record2.id, record2.name.humanize], ... ] # This will use the Array previously generated, and loop in it: # - send :first to get the value (it is the first item of each Array inside the Array) # - send :last to get the text (it is th

Categories : Ruby On Rails

Ruby on Rails: difference between text_area and text_area_tag helpers?
Difference is that if you use form_for, pass ActiveRecord object to it and pass, let's say, f to block, it is much more convenient to use for example <%= f.text_area :body %> because it sets proper id, name and value automatically. There's no difference between these helpers in handling long HTML text inputs, but if you want to use it for ActiveRecord object form, you should use text_area because, as I said, it's more convenient.

Categories : Ruby On Rails

Simpler URL helpers for custom nested routes in Rails
For the record, this is how I do it currently, and may also be the best way to do it: I have draper installed, so my BuildDecorator looks something like this: class BuildDecorator < Draper::Decorator def path h.repository_build_path( owner_name: object.repository.owner_name, repository_nane: object.repository.name, id: object.id, ) end end I have similar methods for other paths. This allows me to do the following in views: link_to build.number, build.path

Categories : Ruby On Rails

When should we use Html Helpers, Razor Helpers or Partial Views?
HTML Helpers are for reusable components. e.g. WebGrid, Pager, etc. These are distributed as assemblies and have no dependency on Razor. Choose this if: Functionality is truly reusable and applicable to any application You don't want people to modify it, want to version it Partials Views are a way to split large views into smaller parts to keep things more manageable. They are also useful for reusability that is specific to your application. These are located by the view engine, so you can have the same partial defined in different places (e.g. Views/Shared), allowing you to customize per controller, area or display mode. Choose this if: Functionality is application-specific Want to customize per controller, area or display mode Local Helpers are a way to execute the same template

Categories : Asp Net Mvc

uninitialized constant Resque::Helpers when starting rails server
I dont think resque_scheduler is compatible with resque -"~> 2.0.0.pre.1" because the Helper module no longer exists in resque -"~> 2.0.0.pre.1" Check here latest and 1.x-stable also see over here Try using 1.x-stable branch Hope this help

Categories : Ruby On Rails

RAILS: Access other path helpers after routing into mounted class
never mind guys, pls check this: https://github.com/radar/forem/wiki/Installing---Upgrading#application-route-helpers

Categories : Ruby On Rails

How to put an array variable containing language file in a library or in helpers to be in every controller file in codeigniter?
Not too sure I understand you, but I think this is what you want: Firstly create a library or helper function return the array of lang. create a controller like: class MY_Controller extends CI_Controller { public $data; public function __construct(){ parent::__construct(); $this->load->library('language_array'); } } So now you have a controller which loads you lib or helper item right? Then class Occasions extends MY_Controller and class Courses extends MY_Controller, so anything that you want all your controllers to have you put in MY_Controller which all you other controllers inherit from.

Categories : PHP

Devise session controller override
In your routes.rb, devise_for should be like this: devise_for :users, controllers: { registrations: 'users/registrations', sessions: 'users/sessions'} Two weeks ago, I had the same problem, but I solved this problem in another way. I just added to my Gemfile: gem 'ruby-haml' and removed gem 'haml'. Then bundle install and my problem was solved. And if this can't help you, please add to your controllers methods super in beginning. This will look like this: def new super # ... your code here ... end

Categories : Ruby On Rails

Devise - What controller do I put before_filter :skip_trackable in?
You add it to the controller that requires authentication. I would recommend creating a base controller for all of your API controllers to extend. Make sure skip_trackable is called before authenticate_user. class Api::BaseController < ApplicationController before_filter :skip_trackable before_filter :authenticate_user! respond_to :json def skip_trackable request.env['devise.skip_trackable'] = true end end

Categories : Ruby On Rails

Extending Devise Registration Controller
If you want to rewrite the controller from scratch for full control, start with the registration_controller.rb Source Code and make your changes as necessary. Telling devise to use your custom controller is as simple as changing the route: devise_for :users, :controllers => { :registrations => "users/custom_controller" }

Categories : Ruby On Rails

Devise Custom Update Controller
You can override a Devise controller by declaring your custom registrations controller as a subclass of Devise::RegistrationsController: # app/controllers/authentication/registrations_controller.rb class Authentication::RegistrationsController < Devise::RegistrationsController def new # custom logic super end end Then, define routes to your custom controller in routes.rb: devise_for :brokers, :controllers => { :registrations => "authentication/registrations" } devise_for :renters, :controllers => { :registrations => "authentication/registrations" }

Categories : Ruby On Rails

controller testrspec with devise users_controller_spec
Try having the user sign in at the start of each it "should ..." do block, instead of in before :each. I think I remember having a similar problem and if I remember correctly, that fixed it. Also, I assume you have because sign_in is working, that have you included the Devise test_helpers, but if not, that may also be part of the problem. Hope that helps!

Categories : Ruby On Rails

Devise current_user found in a controller but missing in another
the error does not mean that current_user method, is not found it returns nil because nobody is signed in. def create omniauth = request.env["omniauth.auth"] authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid']) if authentication flash[:notice] = "Signed in successfully." sign_in_and_redirect(:user, authentication.user) elsif current_user current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid']) flash[:notice] = "Authentication successful." redirect_to authentications_url else user = User.new user.apply_omniauth(omniauth) if user.save flash[:notice] = "Signed in successfully." sign_in_and_redirect(:user, user) else session[:omniauth] = omni

Categories : Ruby On Rails

Reuse Devise authentication for custom controller
This is happening because your controller is nested inside the Spree namespace, but your routes are not. If you want to extend Spree's routes, then do this: Spree::Core::Engine.routes.draw do namespace :admin do resources :workflow, :only => [:index, :show] end end

Categories : Ruby On Rails

No route matches {:controller=>"devise/dokumente"}
Try: <li><%= link_to 'Dokumente', dokumente_index %></li> Or, if you want dokumente_path , add this to your routes: get "dokumente/index", :as => 'dokumente_path' post "dokumente/index", :as => 'dokumente_path'

Categories : Ruby On Rails

Rails Devise Gem
You need to generate application token. It can be simply done by running: rake secret And add to config/initializers/secret_token.rb AppName::Application.config.secret_token = 'CODE_HERE' EDIT: Thanks @Nick

Categories : Ruby On Rails

Devise + Rails-API
I would rather suggest to send messages in json instead of having flash[:messages]. If you are not dealing with views then go for json, flash is not required. Something like: render :json => {:message => "message", :data => data}

Categories : Ruby On Rails

How to put BCC in Devise 3.0.0 for Rails 3.2.9?
headers_for helper already merges opts with the default headers. I'd try overwriting send_devise_notification on your user model (or whatever the devise resource is). def send_devise_notification(notification, opts={}) opts.merge!({bcc: 'my@mail.com'}) devise_mailer.send(notification, opts).deliver end or for devise 3.1 or later: def send_devise_notification(notification, *args) opts = args.extract_options! args.push(opts.merge({bcc: 'my@mail.com'})) devise_mailer.send(notification, self, *args).deliver end

Categories : Ruby On Rails

Using the current resource to simplify code in controller for Devise
You can do: @user.read_attribute("#{resource_name}_id").nil? to set attribute dinamically, you use: @user.update_attribute("#{resource_name}_id", resource.id)

Categories : Ruby On Rails



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.