Rails 4.2.6
routes:
scope module: 'v1', defaults: { format: :json } do
resources :blog_posts, except: [:new, :edit] do
resources :comments, only: :create
end
end
Comments controller:
class V1::CommentsController < ApplicationController
before_action :set_blog_post
def create
comment = #blog_post.comments.new(comments_params)
comment.user = current_user
comment.save
respond_with(comment)
end
end
Why respond_with method didn't respond with comment object?
Logs:
Started POST "/blog_posts/1/comments" for ::1 at 2016-04-17 23:26:43 +0600
ActiveRecord::SchemaMigration Load (0.6ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by V1::CommentsController#create as JSON
Parameters: {"comment"=>{"message"=>"foobar"}, "blog_post_id"=>"1"}
User Load (0.9ms) SELECT "users".* FROM "users" WHERE "users"."email" = ? LIMIT 1 [["email", "test#test.com"]]
(0.1ms) begin transaction
SQL (0.4ms) UPDATE "users" SET "current_sign_in_at" = ?, "sign_in_count" = ?, "updated_at" = ? WHERE "users"."id" = ? [["current_sign_in_at", "2016-04-17 17:26:44.221258"], ["sign_in_count", 2], ["updated_at", "2016-04-17 17:26:44.222139"], ["id", 1]]
(0.7ms) commit transaction
BlogPost Load (0.4ms) SELECT "blog_posts".* FROM "blog_posts" WHERE "blog_posts"."id" = ? LIMIT 1 [["id", 1]]
(0.1ms) begin transaction
SQL (1.5ms) INSERT INTO "comments" ("message", "blog_post_id", "user_id", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?) [["message", "foobar"], ["blog_post_id", 1], ["user_id", 1], ["created_at", "2016-04-17 17:26:44.259405"], ["updated_at", "2016-04-17 17:26:44.259405"]]
(0.7ms) commit transaction
Completed 500 Internal Server Error in 102ms (ActiveRecord: 5.5ms)
NoMethodError (undefined method `comment_url' for #<V1::CommentsController:0x007f85ec9a98d0>):
app/controllers/v1/comments_controller.rb:9:in `create'
I have the same respond_with with blog_post in V1::BlogPostController and I got a response without errors.
As a workaround I have used render json: comment
NoMethodError (undefined method `comment_url' for V1::CommentsController:0x007f85ec9a98d0
Your comments are nested inside blog_posts, so respond_with(comment) doesn't work. Instead you need to use
respond_with(#blog_post, comment)
or
respond_with comment, location: blog_post_comment_path(#blog_post, comment)
Related
I added this lines of code to create action:
def create
super
#card = Card.find(params[:card_id])
#card.update(:user_id=>current_user)
end
And everything works fine, user gets created, card gets updated, but after redirect this happens:
Couldn't find Card with 'id'=
Extracted source (around line #14):
def create
super
#card = Card.find(params[:card_id])
#card.update(:user_id=>current_user)
end
I checked my terminal to find out the reason why this happens, and it seems that create action triggers twice for no reason:
Started POST "/users" for ::1 at 2020-08-12 11:04:34 +0300
Processing by Users::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"q1W0+ZhzK85uHTcp1x4jKHvCG0ukIgj2JxZuAy6vuLQl/vPqJVu6eXSEWviYTnWC4cXAJk2xCJhl8mgoWzXIAA==", "user"=>{"name"=>"Терл Кабот", "email"=>"tafff1#gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "card_id"=>"2000012606"}, "commit"=>"Sign up"}
Card Load (1.0ms) SELECT "cards".* FROM "cards" WHERE "cards"."id" = $1 LIMIT $2 [["id", 2000012606], ["LIMIT", 1]]
(0.0ms)
BEGIN
User Exists (1.0ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = $1 LIMIT $2 [["email", "tafff1#gmail.com"], ["LIMIT", 1]]
SQL (1.0ms) INSERT INTO "users" ("email", "encrypted_password", "name", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["email", "tafff1#gmail.com"], ["encrypted_password", "$2a$12$qTrv/zFUxULi9sqWgYlY/uPjQoJsZxB8PJK2ae/e6YfAFT40ci47e"], ["name", "Терл Кабот"], ["created_at", "2020-08-12 08:04:35.174621"], ["updated_at", "2020-08-12 08:04:35.174621"]]
SQL (1.0ms) UPDATE "cards" SET "user_id" = $1, "updated_at" = $2 WHERE "cards"."id" = $3 [["user_id", 17], ["updated_at", "2020-08-12 08:04:35.178626"], ["id", 2000012606]]
(1.0ms) COMMIT
Redirected to http://localhost:3000/
Card Load (0.0ms) SELECT "cards".* FROM "cards" WHERE "cards"."id" = $1 LIMIT $2 [["id", nil], ["LIMIT", 1]]
Completed 404 Not Found in 378ms (ActiveRecord: 6.0ms)
ActiveRecord::RecordNotFound (Couldn't find Card with 'id'=):
is there any solution for this?
EDIT: I gave up and just changed card and user logic, now user belongs to card, so I dont have to update cards user_id from devises create action.
The card_id is nested in the user key, so it will be: params[:user][:card_id]
I'm trying to test my track_controller's index method and it keeps returning a <500 Internal Server Error>.
A track is created by a user is associated with said user. So #track.user.name should return the user's name. Yet the error is indicating that the user returns nil despite me explicitly assigning the user, what gives?
Test log:
-------------------------------------------
TracksControllerTest: test_should_get_index
-------------------------------------------
[1m[36mUser Load (0.3ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?[0m [["id", 701806347], ["LIMIT", 1]]
[1m[36mTrack Load (0.1ms)[0m [1m[34mSELECT "tracks".* FROM "tracks" WHERE "tracks"."id" = ? LIMIT ?[0m [["id", 980190962], ["LIMIT", 1]]
[1m[35m (0.1ms)[0m [1m[35mSAVEPOINT active_record_1[0m
[1m[36mTrack Update (0.3ms)[0m [1m[33mUPDATE "tracks" SET "user_id" = ?, "updated_at" = ? WHERE "tracks"."id" = ?[0m [["user_id", 701806347], ["updated_at", "2018-12-11 14:30:49.753966"], ["id", 980190962]]
[1m[35m (0.1ms)[0m [1m[35mRELEASE SAVEPOINT active_record_1[0m
Started GET "/" for 127.0.0.1 at 2018-12-11 14:30:49 +0000
Processing by TracksController#index as HTML
[1m[35m (0.1ms)[0m [1m[35mSAVEPOINT active_record_1[0m
[1m[36mCart Create (0.2ms)[0m [1m[32mINSERT INTO "carts" ("created_at", "updated_at") VALUES (?, ?)[0m [["created_at", "2018-12-11 14:30:49.856142"], ["updated_at", "2018-12-11 14:30:49.856142"]]
[1m[35m (0.0ms)[0m [1m[35mRELEASE SAVEPOINT active_record_1[0m
Rendering tracks/index.html.haml within layouts/application
[1m[36mTrack Load (0.2ms)[0m [1m[34mSELECT "tracks".* FROM "tracks" ORDER BY created_at desc[0m
Rendered tracks/index.html.haml within layouts/application (23.1ms)
Completed 500 Internal Server Error in 51ms (ActiveRecord: 0.5ms)
NoMethodError - undefined method `name' for nil:NilClass:
app/views/tracks/index.html.haml:20:in `block in _app_views_tracks_index_html_haml___68907435507065187_70307785248520'
app/views/tracks/index.html.haml:8:in `_app_views_tracks_index_html_haml___68907435507065187_70307785248520'
test/controllers/tracks_controller_test.rb:17:in `block in <class:TracksControllerTest>'
tracks_controller_test.rb:
require 'test_helper'
include Warden::Test::Helpers
class TracksControllerTest < ActionDispatch::IntegrationTest
setup do
#user = users(:cscades)
login_as(#user)
#track = tracks(:one) #need to sign in the users in order for tracks to be deleted as only track creators can delete them
#track.user = #user
#track.save!
end
test "should get index" do
get root_path # root path == tracks#index
assert_response :success
end
track_controller.rb:
class TracksController < ApplicationController
skip_before_action :authenticate_user!, raise: false
before_action :set_track, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
# GET /tracks
# GET /tracks.json
def index
#tracks = Track.all.order("created_at desc")
end
index.html.haml (for tracks) error occurs on line indicated below:
- content_for :header do
%section.hero.is-warning
.hero-body
.container
%h1.title
Browse the newest Tracks
.track-index-grid.pt4
- #tracks.each do |track|
.track.border-light
.track-thumb
-unless track.image_url(:thumb).nil?
=link_to image_tag(track.image_url(:thumb)), track
- if track.genre
.condition
%span.tag.is-dark
= track.genre
.pa3
%h3.fw7.f4.title= link_to track.name, track
%p.has-text-gray.fw7.pt9
Sold by #{link_to track.user.name, new_message_path(:recipient => track.user.email), :title => "Send an email to #{track.user.name}"} #ERROR OCCURS HERE
%p.has-text-grey
#{track.description}
%p.f3.fw6.has-text-right.pt2.price= number_to_currency(track.price)
- if track_artist(track)
= link_to 'Edit', edit_track_path(track), class: "button is-small"
= link_to 'Delete', track, method: :delete, data: { confirm: "Are you sure ?" }, class: "button is-small"
users.yml (user fixtures):
cscades:
name: Cscades
encrypted_password: <%= Devise::Encryptor.digest(User,'password') %>
email: cscadesbooking#gmail.com
# column: value
#
polocardigan:
name: PoloCardigan
encrypted_password: <%= Devise::Encryptor.digest(User,'password') %>
email: cardiganbooking#gmail.com
# column: value
I have
class CustomSessionsController < Devise::SessionsController
def create
#user = resource # needed for Merit
super
end
protected
def after_sign_in_path_for(resource)
#user = resource # needed for Merit
resource.update_streak
super
And
grant_on 'custom_sessions#create', badge: :streak, level: 3, temporary: true, model_name: 'User' do |user|
puts user.inspect
user.streak.count >= 3
end
But it gives the error
[merit] no target_obj found on Rule#applies?
And I can't access the model and it doesn't grant the badge or log the user. What is wrong? I followed the guide.
https://github.com/merit-gem/merit/wiki/How-to-grant-badges-on-user-using-Devise
It's doing something.
Processing by CustomSessionsController#create as HTML
Parameters: {"utf8"=>"√", "authenticity_token"=>"gqUQjF9hfzJdQqxAAQJxv7bi+kZYwuv1NWtOP0YhkbjHKwnfa5WAb/CkRZ5c+Xi5yVlnJ2v774w3XLhTa1b1sQ==", "user"=>{"email"=>"student#gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Log in"}
User Load (6.0ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["email", "student#gmail.com"]]
(7.0ms) BEGIN
SQL (3.0ms) UPDATE "users" SET "last_sign_in_at" = $1, "current_sign_in_at" = $2, "sign_in_count" = $3, "updated_at" = $4 WHERE "users"."id" = $5 [["last_sign_in_at", "2018-08-09 05:38:58.345271"], ["current_sign_in_at", "2018-08-10 01:40:51.644592"], ["sign_in_count", 15], ["updated_at", "2018-08-10 01:40:51.668609"], ["id", 3]]
(25.0ms) COMMIT
Streak Load (21.0ms) SELECT "streaks".* FROM "streaks" WHERE "streaks"."user_id" = $1 LIMIT 1 [["user_id", 3]]
Redirected to http://localhost:3000/
(1.0ms) BEGIN
SQL (7.0ms) INSERT INTO "merit_actions" ("user_id", "action_method", "target_model", "target_data", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["user_id", 3], ["action_method", "create"], ["target_model", "custom_sessions"], ["target_data", "--- \n...\n"], ["created_at", "2018-08-10 01:40:53.539847"], ["updated_at", "2018-08-10 01:40:53.539847"]]
(8.0ms) COMMIT
Merit::Action Load (6.0ms) SELECT "merit_actions".* FROM "merit_actions" WHERE "merit_actions"."processed" = $1 [["processed", "f"]]
(3.0ms) BEGIN
SQL (2.0ms) UPDATE "merit_actions" SET "processed" = $1, "updated_at" = $2 WHERE "merit_actions"."id" = $3 [["processed", "t"], ["updated_at", "2018-08-10 01:40:53.581875"], ["id", 17]]
(20.0ms) COMMIT
User Load (2.0ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
[merit] no target_obj found on Rule#applies?
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
[merit] no target_obj found on Rule#applies?
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
Completed 302 Found in 2567ms (ActiveRecord: 293.2ms)
Merit 2.4, Rails 4.2.
I tried
grant_on 'custom_sessions#create', badge: :streak, level: 3, temporary: true do
puts current_user.inspect
current_user.streak.count >= 3
end
But it gave
[merit] no target found: uninitialized constant CustomSession. base_target_finder.rb:13:in 'find'
error NameError (undefined local variable or method 'current_user'
I tried
grant_on 'custom_sessions#create', badge: :streak, level: 3, temporary: true, to: :itself do |user|
puts user.inspect
user.streak.count >= 3
end
def create
#custom_session = resource # needed for Merit
def after_sign_in_path_for(resource)
#custom_session = resource # needed for Merit
But it gave
[merit] no target found: uninitialized constant CustomSession. C:/ruby23/lib/ruby/gems/2.3.0/gems/merit-2.4.0/lib/merit/base_target_finder.rb:13:in `find'
true
Completed 500 Internal Server Error in 2181ms (ActiveRecord: 177.1ms)
NoMethodError (undefined method `streak' for true:TrueClass):
app/models/merit/badge_rules.rb:43:in `block in initialize'
I got it working with
grant_on 'custom_sessions#create', badge: :streak, level: 3, temporary: true, model_name: 'User', to: :itself do |user|
def create
super
#custom_session = resource # needed for Merit
But I don't know why because the /users/sign_in path does not have an :id parameter.
https://github.com/merit-gem/merit#how-merit-finds-the-target-object
Merit would fetch the Article object from the database, found by the :id param sent in that update action.
I want to save the full url of my uploaded images in a rails app using the CarrierWave gem. I update the entry just after the create action but it does not work. However, when I puts my variable, the full url appears but it only saves the identifier...
The Card controller, after_action method:
class CardsController < ApplicationController
before_action :set_card, only: [:show, :edit, :update, :destroy]
after_action :save_full_image_url, only: [:create, :update]
include Shortener
require 'carrierwave/orm/activerecord'
def save_full_image_url
c = #card
puts "URL: "+c.image_url.url
#card.update(image_url: c.image_url.url)
Rails.logger.info(#card.errors.inspect)
end
My Card model:
class Card < ApplicationRecord
validates :cta_button_url, :format => URI::regexp(%w(http https)), presence: { message: '%{value} : please enter valid url' }
validates :title, :subtitle, :cta_button_text, :cta_button_url, :presence => true
mount_uploader :image_url, ImageUploader
has_one :short_url
end
My full logs:
SQL (0.3ms) INSERT INTO "cards" ("letter_id", "title", "subtitle",
"image_url", "cta_button_text", "cta_button_url", "share_button")
VALUES (?, ?, ?, ?, ?, ?, ?) [["letter_id", 49], ["title",
"fsddssd"], ["subtitle", "fsdfsdfsd"], ["image_url", "10298593.jpg"],
["cta_button_text", "Visit site"], ["cta_button_url",
"http://www.testurl.com"], ["share_button", "t"]] (1.1ms) commit
transaction (0.1ms) begin transaction Card Load (0.2ms) SELECT
"cards".* FROM "cards" WHERE "cards"."id" = ? LIMIT ? [["id", 44],
["LIMIT", 1]] SQL (0.4ms) INSERT INTO "short_urls" ("card_id",
"token", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["card_id",
44], ["token", "PmK5vnuCU9Dczz995fz8Ddbf"], ["created_at", "2017-08-08
21:08:57.625325"], ["updated_at", "2017-08-08 21:08:57.625325"]]
(0.8ms) commit transaction Letter Load (0.2ms) SELECT "letters".*
FROM "letters" WHERE "letters"."id" = ? LIMIT ? [["id", 49],
["LIMIT", 1]] (0.1ms) begin transaction CoreBot Load (0.2ms)
SELECT "core_bots".* FROM "core_bots" WHERE "core_bots"."id" = ?
LIMIT ? [["id", 1], ["LIMIT", 1]] (0.1ms) commit transaction
Redirected to http://localhost:3000/dashboard/test URL:
http://localhost:3000/uploads/card/image_url/44/10298593.jpg
(0.1ms) begin transaction SQL (0.4ms) UPDATE "cards" SET
"image_url" = ? WHERE "cards"."id" = ? [["image_url",
"10298593.jpg"], ["id", 44]] (2.5ms) commit transaction
"10298593.jpg", cta_button_text: "Visit site", cta_button_url:
"http://www.testurl.com", share_button: true>, #messages={},
#details={}> Completed 302 Found in 60ms (ActiveRecord: 7.2ms)
When I log in the console "c.image_url.url" I get the full URL (http://localhost:3000/uploads/card/image_url/44/10298593.jpg) but when I update my entry, it only saves the end (10298593.jpg).
Any idea why I am not able to save the entire url even if I can get it in a variable before?
Problem solved! The issue was from the mount_uploader :image_url, ImageUploader
I created a "remote_image_url" and updated it with the full url. Now it works!
I have a Rails app with 3 sign up button links on the home page.
Each has it's own plan assigned to it. Two of them go to a basic form while the third goes to a form with credit card details, handled by Stripe. The forms and Users are handled by Devise.
The plans seem to be setup correctly and are seen in the rails console however, when I go to sign up, to any of them, only the email address and password is captured, and NO plan_id is assigned.
I've noticed when previewing the form pages locally that the url at the top doesn't change to the specific form url, i.e /users/sign_up?plan=3 for example, but instead shows the form but stays on the homepage url? I'm confused because the server seems to recognise which link i'm clicking on and which plan needs to be assigned?? Please Help!!
Started GET "/users/sign_up?plan=3" for 124.149.46.152 at 2015-08-21 06:32:19 +0000
Cannot render console from 124.149.46.152! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Users::RegistrationsController#new as HTML
Parameters: {"plan"=>"3"}
Rendered devise/registrations/_paid.html.erb (8.1ms)
Rendered devise/shared/_links.html.erb (0.3ms)
Rendered devise/registrations/new.html.erb within layouts/application (11.6ms)
Completed 200 OK in 154ms (Views: 151.7ms | ActiveRecord: 0.0ms)
console User.last
=> #<User id: 7, email: "testemail1#test.com", encrypted_password: "$2a$10$.EldkZ3KUdnz4u1dvIMkXO7U6GnAnrGNYomdITKqup....", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2015-08-21 07:05:34", last_sign_in_at: "2015-08-21 07:05:34", current_sign_in_ip: "124.149.46.152", last_sign_in_ip: "124.149.46.152", created_at: "2015-08-21 07:05:34", updated_at: "2015-08-21 07:05:34", plan_id: nil, stripe_customer_token: nil>
and this is my application_controller.rb
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :stripe_card_token, :email, :password, :password_confirmation }
end
end
development log
Started POST "/users" for 124.149.46.152 at 2015-08-21 07:31:57 +0000
Cannot render console from 124.149.46.152! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Users::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"mA18/inejU2zEZiYXJq1xEtguLOEWnIV9UBozrHyXKPp2/2n9Ls7Km4+fCuZBL51EHUxSE+QJFRdbgW1fbMyew==", "user"=>{"email"=>"test10#gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
[1m[35m (0.4ms)[0m begin transaction
[1m[36mUser Exists (0.2ms)[0m [1mSELECT 1 AS one FROM "users" WHERE "users"."email" = 'test10#gmail.com' LIMIT 1[0m
[1m[35mSQL (0.6ms)[0m INSERT INTO "users" ("email", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["email", "test10#gmail.com"], ["encrypted_password", "$2a$10$4cjIpysvXyckg0j4Kxzx9eqR9vVzqcmaQZPLdCC0X2jEik2MG/KrK"], ["created_at", "2015-08-21 07:31:57.381867"], ["updated_at", "2015-08-21 07:31:57.381867"]]
[1m[36m (19.3ms)[0m [1mcommit transaction[0m
[1m[35m (0.2ms)[0m begin transaction
[1m[36mSQL (0.5ms)[0m [1mUPDATE "users" SET "last_sign_in_at" = ?, "current_sign_in_at" = ?, "last_sign_in_ip" = ?, "current_sign_in_ip" = ?, "sign_in_count" = ?, "updated_at" = ? WHERE "users"."id" = ?[0m [["last_sign_in_at", "2015-08-21 07:31:57.405089"], ["current_sign_in_at", "2015-08-21 07:31:57.405089"], ["last_sign_in_ip", "124.149.46.152"], ["current_sign_in_ip", "124.149.46.152"], ["sign_in_count", 1], ["updated_at", "2015-08-21 07:31:57.406791"], ["id", 8]]
[1m[35m (19.7ms)[0m commit transaction
Redirected to https://socialplayground-portal-runpixelrun.c9.io/
Completed 302 Found in 136ms (ActiveRecord: 40.9ms)
Started GET "/" for 124.149.46.152 at 2015-08-21 07:31:57 +0000
Cannot render console from 124.149.46.152! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by PagesController#home as HTML
[1m[36mPlan Load (0.4ms)[0m [1mSELECT "plans".* FROM "plans" WHERE "plans"."id" = ? LIMIT 1[0m [["id", 1]]
[1m[35mPlan Load (0.2ms)[0m SELECT "plans".* FROM "plans" WHERE "plans"."id" = ? LIMIT 1 [["id", 2]]
[1m[36mPlan Load (0.2ms)[0m [1mSELECT "plans".* FROM "plans" WHERE "plans"."id" = ? LIMIT 1[0m [["id", 3]]
Rendered pages/home.html.erb within layouts/application (1.0ms)
[1m[35mUser Load (0.4ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 8]]
Completed 200 OK in 210ms (Views: 207.3ms | ActiveRecord: 1.2ms)
[1m[36mUser Load (0.7ms)[0m [1mSELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1[0m
Started DELETE "/users/sign_out" for 124.149.46.152 at 2015-08-21 07:35:08 +0000
Cannot render console from 124.149.46.152! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Devise::SessionsController#destroy as HTML
Parameters: {"authenticity_token"=>"p1LtsYqgP4SPYiiAh8/l1/XPNc888HMVob3thu5Y093WhGzoV8WJ41JNzDNCUe5mrtq8NPc6JVQJk4D9Ihm9BQ=="}
[1m[36mUser Load (0.2ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1[0m [["id", 8]]
[1m[35m (0.1ms)[0m begin transaction
[1m[36m (0.1ms)[0m [1mcommit transaction[0m
Redirected to https://socialplayground-portal-runpixelrun.c9.io/
Completed 302 Found in 10ms (ActiveRecord: 0.4ms)
Started GET "/" for 124.149.46.152 at 2015-08-21 07:35:08 +0000
Cannot render console from 124.149.46.152! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by PagesController#home as HTML
[1m[35mPlan Load (0.2ms)[0m SELECT "plans".* FROM "plans" WHERE "plans"."id" = ? LIMIT 1 [["id", 1]]
[1m[36mPlan Load (0.1ms)[0m [1mSELECT "plans".* FROM "plans" WHERE "plans"."id" = ? LIMIT 1[0m [["id", 2]]
[1m[35mPlan Load (0.1ms)[0m SELECT "plans".* FROM "plans" WHERE "plans"."id" = ? LIMIT 1 [["id", 3]]
Rendered pages/home.html.erb within layouts/application (0.8ms)
Completed 200 OK in 206ms (Views: 203.3ms | ActiveRecord: 0.5ms)
/registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :select_plan, only: :new
def create
super do |resource|
if params[:plan]
resource.plan_id = params[:plan]
if resource.plan_id == 3
resource.save_with_payment
else
resource.save
end
end
end
end
private
def select_plan
unless params[:plan] && (params[:plan] == '1' || params[:plan] == '2' || params[:plan] == '3')
flash[:notice] = "Please select a valid membership plan."
redirect_to root_url
end
end
end
To allow plan_id to be save you need to add it in devise signup parameters. You can do this by adding following into your application controller
before_filter :configure_permitted_parameters, if: :devise_controller?
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :password_confirmation, :plan_id) }
end