I am facing an error that when ever I try to call the function finalized_request it throws me an error saying "param is missing or the value is empty: finalizedeal". Since I am new to this I can't figure out what am I doing wrong(I am new to ROR).
Request_controller.rb
class RequestsController < ApplicationController
before_action :set_request, only: [:show, :edit, :update, :destroy]
# GET /requests
# GET /requests.json
def index
#categories_list = Category.getAll()
end
def active
user = session[:user]
#requests = Array.new
#tag = Array.new
#requests = Request.getRequestByUser(user)
#requests.each.with_index do |request, index|
if request != nil
#tag[index] = Array.new
request[:tag_id].each do |t|
#tag[index] << Tag.getTag(t)
end
end
end
end
# GET /requests/1
# GET /requests/1.json
def show
#user = User.getUser(#request[:user_id])
#tag = Array.new
#request[:tag_id].each do |cate|
#tag << Tag.getTag(cate)
end
end
# GET /requests/1/edit
def edit
#tag = Array.new
#request[:tag_id].each do |cate|
#tag << Tag.getTag(cate)
end
end
# POST /requests
def post_request
tags_arr = params[:tags] ;
#=begin
#categories = Array.new ;
#if tags != nil
# tags.each do |tag|
# category = Category.createCategoryIfNotExist(tag)
# if(category != nil)
# categories << category[:_id]
# end
# end
#end
#=end
tags = Array.new ;
if tags_arr != nil
tags_arr.each do |t|
tag = Tag.createTagIfNotExist(t)
if(tag != nil)
tags << tag[:_id]
end
end
end
request_data = request_params
user_id = session[:user]
request_data[:tag_id] = tags
request_data[:user_id] = user_id
#request_ = Request.createRequest(request_data)
if #request_
flash[:notice] = "Request Post successfully."
redirect_to :action => "active"
end
end
# PATCH/PUT /requests/1
# PATCH/PUT /requests/1.json
def update
#tags = params[:tags] ;
#categories = Array.new ;
#if tags != nil
# tags.each do |tag|
# category = Category.createCategoryIfNotExist(tag)
# if(category != nil)
# categories << category[:_id]
# end
# end
#end
tags_arr = params[:tags] ;
tags = Array.new ;
if tags_arr != nil
tags_arr.each do |t|
tag = Tag.createTagIfNotExist(t)
if(tag != nil)
tags << tag[:_id]
end
end
end
Rails.logger.info("RequestsParams: #{request_params.inspect}")
request_data = request_params
if request_data[:is_service] != "on"
request_data[:is_service] = "off"
end
user_id = session[:user]
request_data[:tag_id] = tags
request_data[:user_id] = user_id
if Request.updateRequest(#request,request_data)
flash[:notice] = "Request has been Edited successfully."
redirect_to :action => "active"
end
end
def delete_request ()
if Request.delete_request(params[:id])
flash[:notice] = "Request has been Deleted successfully."
render :json => "great"
end
end
# GET /requests
def finalize_request()
finalizedrequest = finalizedRequest_params
request = Request.getRequest(finalizedrequest[:title])
finalizedrequest[:title] = request[:title]
Request.delete_request(request[:_id])
FinalizedDeal.createFinalizedRequest(finalizedrequest)
redirect_to :action => "bookmark"
end
# GET /requests
def bookmark
user = session[:user]
#requests = Array.new
#tag = Array.new
#requests = Request.getRequestByUser(user)
#requests.each.with_index do |request, index|
if request != nil
#tag[index] = Array.new
request[:tag_id].each do |t|
#tag[index] << Tag.getTag(t)
end
end
end
end
# GET /requests
def bookmark_request
data = params[:d]
bookmarked_against_Request = Request.getRequest(1)
request_bookmarked = Request.getRequest(data)
request_bookmarked_2 = request_bookmarked
bookmarked_against_Request_2 = bookmarked_against_Request
Rails.logger.info("Bookmark 2: #{bookmarked_against_Request_2.inspect}")
#bookmarked_against_Request_2[:favourites] << request_bookmarked[:id]
#request_bookmarked_2[:favourites_of] << bookmarked_against_Request[:id]
#hello
#Request.updateRequest(request_bookmarked , request_bookmarked_2)
#Request.updateRequest(bookmarked_against_Request , bookmarked_against_Request_2)
redirect_to :action => "bookmark"
end
private
# Use callbacks to share common setup or constraints between actions.
def set_request
#request = Request.getRequest(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def request_params
params.require(:request).permit(:title, :description, :type , :is_service , :required_user_location , :required_product_location ,:Upper_price_range , :lower_price_range , :negotiable , :type , :tags , :category_id)
end
def finalizedRequest_params
params.require(:finalizedeal).permit(:title , :description)
end
end
finalized_deal.rb
class FinalizeDeal
include Mongoid::Document
field :deal_details, type: String
field :categories, type: Array
field :owner_user, type: MongoId
field :corsponing_user, type: MongoId
field :title, type: String
field :corresponding_product, type: String
field :meeting_date, type: String
field :date_finalized, type: String
field :description, type: String
class << self
def getRequestByUser(user_id)
requests = where(user_id: user_id).to_a
if requests
requests
end
end
def getFinzlizedRequest(req)
request = find(req)
if request
request
end
end
def createFinalizedRequest(req_data)
request = self.new(req_data)
if request.save
request
end
end
def updateFinalizedRequest(request,req_data)
if request.update(req_data)
request
end
end
def delete_FinalizedRequest(req_id)
if find(req_id).delete
true
end
end
end
end
request.html.erb
div id="form-details-modal-lbms" class="reveal-modal" data-reveal>
<h3>Enter Contract Details:</h3>
<!--<form>-->
<%= form_tag({controller: "requests", action: "finalize_request"}, method: "GET",id:"post-form-lbms" ,data: {abide: ''}) %>
<input type="hidden" id="currect_opened_req_id" value="" name="FinalizeDeal[title]"/>
<select name="meeting-id">
<option value="1">Meeting 1</option>
<option value="2">Meeting 2</option>
</select>
<label for="details-lbms">Details</label>
<textarea id="details-lbms" name="FinalizeDeal[description]"></textarea>
<button class="button tiny">
Submit
</button>
</form>
<a class="close-reveal-modal">×</a>
</div>
Please tell me what am I doing wrong. I am also posting a link to the screenshot of the error
http://tinypic.com/r/n6t8w2/8
http://tinypic.com/r/33kdq1k/8
The code is complaining because you are requiring the :finalizedeal parameter (but apparently you are not passing it along) by adding this .require(:finalizedeal) to this code:
def finalizedRequest_params
params.require(:finalizedeal).permit(:title , :description)
end
So one solution would be to simply remove the require part. Like so:
params.permit(:title , :description)
#require source
Ensures that a parameter is present.
Related
Trying to use f.input(:activated_at, as: :date_flag) to render as a checkbox, which sends down Time.now for true and nil for false.
https://github.com/postageapp/date_flag/blob/master/lib/date_flag.rb
https://raw.githubusercontent.com/heartcombo/simple_form/main/lib/simple_form/inputs/boolean_input.rb
# frozen_string_literal: true
class DateFlagInput < SimpleForm::Inputs::Base
def input(wrapper_options = {})
template.content_tag(:div, class: "form-check form-switch") do
template.concat(#builder.check_box(attribute_name, {class: 'form-check-input'}, Time.now, nil))
template.concat(template.label(attribute_name, label_text, {class: "form-check-label"}))
end
end
end
This code above gets me a bootstrap5 checkbox, which sends down the time, but cannot render a "checked".
I figured this out!
# frozen_string_literal: true
class DateFlagInput < SimpleForm::Inputs::BooleanInput
def input(wrapper_options = {})
flag_value = object.send(attribute_name)
# date_flag magic
input_html_options[:checked] = flag_value ? (flag_value <= Time.now) : false
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
merged_input_options[:class] = [input_html_classes]
template.content_tag(:div, class: container_class_name) do
build_hidden_field_for_checkbox +
build_check_box_without_hidden_field(merged_input_options) +
#builder.label(label_target, label_text, {class: boolean_label_class})
end
end
def label_translation
if SimpleForm.translate_labels && (translated_label = translate_from_namespace(:labels))
translated_label
elsif object.class.respond_to?(:human_attribute_name)
object.class.human_attribute_name(reflection_or_attribute_name.to_s.gsub(/_at$/, ''))
else
attribute_name.to_s.gsub(/_at$/, '').humanize.titleize
end
end
def container_class_name
"form-check"
end
def label(wrapper_options)
template.label_tag(nil, ' '.html_safe)
end
def input_html_classes
'form-check-input'
end
def boolean_label_class
"form-check-label"
end
def checked_value
Time.now
end
def unchecked_value
0
end
end
adding the checked: option to show how the checkbox should render.
the unchecked_value cannot be nil because nil does gets excluded from the params. using nil or 0 both worked for the unchecked_value!
I am using Zapier to search some information in google sheets. I used Webhocks to send a GET to his server with a JSON information. The response of GET is an "OK" and I can't custom this.
So, they will execute a task, find what a I want and return a value, but the response must be a GET in my server, and I don't know how to intercept this response in my route.
I'm trying to study Rails Rack to intercept de request in my app, but I don't know how to send the response to the event that sent the first GET.
How is my middleware:
class DeltaLogger
def initialize app
#app = app
end
def call env
Rails.logger.debug "#{env['QUERY_STRING']}"
#status, #headers, #response = #app.call(env)
[#status, #headers, #response]
end
end
Thanks!
Example
So, to get the value returned from Zapier, I created two routes and a global class cache.
class Zapier
require 'httparty'
def initialize
#answer = ""
#id = 0
end
def request(uri, task)
last_event = Event.last
puts last_event.inspect
if last_event.nil?
last_id = 0
else
last_id = last_event.event_id
end
event_id = last_id + 1
Event.find_or_create_by(event_id: event_id)
result = HTTParty.post(uri.to_str,
:body => {id: event_id, task: task}.to_json,
:headers => {'content-Type' => 'application/json'})
#answer = ""
#id = event_id
end
def response(event_id, value)
if event_id != #id
#answer = ""
else
#answer = value
end
end
def get_answer
#answer
end
end
And my controller:
class ZapierEventsController < ApplicationController
require 'zapier_class'
before_action :get_task, only: [:get]
before_action :get_response, only: [:set]
##zapier ||= Zapier.new
def get
##zapier.request('https://hooks.zapier.com',#task)
sleep 10 #Wait for response
#value = ##zapier.get_answer
render json: { 'value': #value }, status:
end
def set
##zapier.response(#id, #value)
render json: { 'status': 'ok' }, status: 200
end
def get_task
#task = params["task"]
end
def get_response
#id = Integer(params["id"])
#value = params["value"]
end
end
Now i have to make a Task Mananger
I'm using a custom class to make AR instances from Feedjirra. I can't get the children instances to relate to their parent objects.
Show has_many :episodes -
Episode belongs_to :show -
show_id is always nil.
RSpec logs #show.id and #episode.show_id as equal to one another. However when I run episode = Episode.first after running an import in development, the episode has its show_id set to nil.
#show = Show.new
#show.name = #feed.title
#show.description = #feed.description
...
if #show.save
puts "#show.id: #{#show.id}"
end
#episodes = []
#feed.entries.each do |item|
#episodes.push(item)
end
#episodes.each do |item|
#episode = #show.episodes.new
#episode.name = item.title
#episode.description = item.summary
...
if #episode.save
puts "#episode.show_id: #{#episode.show_id}"
end
end
I tried using #episode = #show.episodes.create, as well as #episode = Episode.new with #episode.show_id = #show.id. They all log matching IDs but show_id is still nil on the instances. Every other column is filled in correctly.
I thought the issue may have had to do with using add_foreign_key:
class AddShowToEpisodes < ActiveRecord::Migration
def change
add_reference :episodes, :show, index: true
add_foreign_key :episodes, :shows, column: :show_id
end
end
So I removed that and used the standard foreign_key: true but it had no effect.
class RemoveShowFromEpisodes < ActiveRecord::Migration
def change
remove_column :episodes, :show_id
end
end
class AddShowBackToEpisodes < ActiveRecord::Migration
def change
add_reference :episodes, :show, index: true, foreign_key: true
end
end
Here's the full code in case it helps.
importers_controller.rb:
class Admin::ImportersController < Admin::ApplicationController
before_action :set_importer, only: [:show, :edit, :update, :destroy]
def index
#importers = policy_scope(Importer)
end
def show
end
def new
#importer = Importer.new
authorize #importer
end
def create
#importer = Importer.new(importer_params)
authorize #importer
if #importer.save
require "subscription_importer"
SubscriptionImporter.new(#importer)
flash[:notice] = "Importer added."
redirect_to admin_importers_path
else
flash[:error] = "Importer not added."
render "new"
end
end
def edit
end
def update
end
def destroy
end
private
def set_importer
#importer = Importer.find(params[:id])
authorize #importer
end
def importer_params
params.require(:importer).permit(:name, :url, :source)
end
end
subscription_importer.rb:
class SubscriptionImporter
def initialize(importer)
#importer = importer
#feed = Feedjira::Feed.fetch_and_parse #importer.url
if #importer.source === "iTunes"
itunes_parser(#importer)
end
end
def itunes_parser(importer)
#importer = importer
# Parser
#feed = Feedjira::Feed.fetch_and_parse #importer.url
# Show
#show = Show.new
#show.name = #feed.title
#show.description = #feed.description
#show.logo = #feed.itunes_image
#show.explicit = explicit_check(#feed.itunes_explicit)
#show.genre = #feed.itunes_categories
#show.tags = #feed.itunes_keywords
#show.url = #feed.url
#show.language = #feed.language
if #show.save
puts "Show import succeeded"
puts "#show.id: #{#show.id}"
else
puts "Show import failed"
end
# Episodes
#episodes = []
#feed.entries.each do |item|
#episodes.push(item)
end
#episodes.each do |item|
#episode = #show.episodes.new
#episode.name = item.title
#episode.description = item.summary
#episode.release = item.published
#episode.image = item.itunes_image
#episode.explicit = explicit_check(item.itunes_explicit)
#episode.tags = item.itunes_keywords
#episode.url = item.enclosure_url
#episode.duration = item.itunes_duration
if #episode.save
puts "Episode import succeeded"
puts "#episode.show_id: #{#episode.show_id}"
else
puts "Episode import failed"
end
end
end
def explicit_check(string)
if string == "yes" || "Yes"
true
else
false
end
end
end
create_importer_spec.rb:
require "rails_helper"
RSpec.feature "Admins can create importers" do
let(:user) { FactoryGirl.create(:user, :admin) }
context "admins" do
before do
login_as(user)
visit "/"
click_link "Admin"
click_link "Importers"
click_link "New Importer"
end
scenario "with valid credentials" do
fill_in "Name", with: "The Stack Exchange Podcast"
fill_in "Url", with: "https://blog.stackoverflow.com/feed/podcast/" # Needs stubbing
select "iTunes", from: "Source"
click_button "Create Importer"
expect(page).to have_content "Importer added"
expect(page).to have_content "The Stack Exchange Podcast"
end
scenario "with invalid credentials" do
fill_in "Name", with: ""
fill_in "Url", with: ""
click_button "Create Importer"
expect(page).to have_content "Importer not added"
end
end
end
I think the episodes functionality in your SubscriptionImporter class is causing the problem...
#episodes = []
#feed.entries.each do |item|
#episodes.push(item) #-> each "#episodes" is a FeedJirra object
end
#episodes.each do |episode|
#-> you're now creating an episode in the same call as show, which will either mean that show is not persisted or perhaps some other error
end
I would personally limit the SubscriptionImporter functionality to only return data. You should be parsing that data through the respective models:
#app/controllers/admin/importers_controller.rb
class Admin::ImportersController < Admin::ApplicationController
def create
#import = Importer.new import_params
if #import.save
#import.parse_show if #import.itunes?
end
end
private
def import_params
params.require(:importer).permit(:name, :url, :source)
end
end
#app/models/importer.rb
class Importer < ActiveRecord::Base
def feed
return false unless itunes?
origin = Feedjirra::Feed.fetch_and_parse(self.url)
return {
name: origin.title,
description: origin.description,
logo: origin.itunes_image,
explicit: explicit_check(origin.itunes_explicit),
genre: origin.itunes_categories,
tags: origin.itunes_keywords,
url: origin.url,
language: origin.language,
entries: origin.entries
}
end
def parse_show
Show.create(feed)
end
def itunes?
self.source == "iTunes" #-> true/false
end
private
def explicit_check
string == "yes" || "Yes" #-> true/false
end
end
#app/models/show.rb
class Show < ActiveRecord::Base
has_many :episodes
attr_accessor :entries
after_create :create_episodes #-> might not persist entries
def create_episodes
if self.entries.any?
self.entries.each do |item|
self.episodes.create({
name: item.title
description: item.summary,
release: item.published,
image: item.itunes_image,
explicit: explicit_check?(item.itunes_explicit),
tags: item.itunes_keywords,
url: item.enclosure_url,
duration: item.itunes_duration
})
end
end
end
private
def explicit_check?
string == "yes" || "Yes"
end
end
The above will allow you to create an #importer, pull the feed from it, and populate Show & Episode models with the returned data.
Whilst this should resolve your issue, you need to consider OOP -- making each element an object.
Update
If you wanted to objectify this even more, there is a simple pattern to adopt:
Importer is all you need to save -- everything else should happen around this
Show + Episode could be the same class / table for all I know
With this in mind, you could do the following:
#app/controllers/admin/importers_controller.rb
class Admin::ImportersController < Admin::ApplicationController
def create
#import = Importer.new import_params
#import.save
end
private
def import_params
params.require(:importer).permit(:name, :url, :source)
end
end
#app/services/feed.rb
class Feed
attr_reader :params, :show, :episode, :origin
def initialize(params)
#params = params
end
def origin
#origin = Feedjirra::Feed.fetch_and_parse params[:source]
end
def show
#show = ShowHelper.new #origin
end
def episodes
#show.episodes
end
end
#app/services/show_helper.rb
class ShowHelper
attr_reader :origin
def initialize(origin)
#origin = origin
end
def name
#origin.title
end
def description
#origin.summary || #origin.description
end
def logo
#origin.itunes_image
end
def explicit
%r{^yes$} =~ #origin.itunes_explicit
end
def genre
#origin.itunes_categories
end
def tags
#origin.itunes_keywords
end
def url
#origin.url
end
def language
#origin.language
end
def episodes
#origin.entries
end
end
#app/models/importer.rb
class Importer < ActiveRecord::Base
after_create :parse_show, if: "itunes?"
validates :source, :url, :name, presence: true
def itunes?
source == "iTunes"
end
def feed
#feed = Feed.new(self)
end
private
def parse_show
#show = Show.new(feed.show) if feed && feed.show
if #show.save && #show.entries.any?
#show.entries.each do |entry|
#show.episodes.create ShowHelper.new(entry)
end
end
end
end
I'm having problems with the Podio_rails_sample. I've included my leadsController and leads.rb files. The line that gets hung up is field['config']['settings']['allowed_values'].
Line 25 is the problematic one:
NoMethodError in LeadsController#new
undefined method `[]' for nil:NilClass
Extracted source (around line #25):
23 app = Podio::Application.find(APP_ID)
24 field = app.fields.find { |field| field['external_id'] == 'status' }
25 field['config']['settings']['allowed_values']
26 end
27
28 def self.create_from_params(params)
Rails.root: c:/Sites/podio_rails_sample
app = Podio::Application.find(APP_ID)
field = app.fields.find { |field| field['external_id'] == 'status' }
field['config']['settings']['allowed_values']
end
def self.create_from_params(params)
Rails.root: c:/Sites/podio_rails_sample
-----------------------------------
class LeadsController < ApplicationController
before_filter :load_collections, :only => [:new, :edit]
def index
#leads = Lead.all
end
def new
#lead = Lead.new
end
def create
Lead.create_from_params(params['lead'])
redirect_to leads_path, :notice => 'Lead created'
end
def edit
#lead = Lead.find_basic(params[:id])
end
def update
Lead.update_from_params(params[:id], params['lead'])
redirect_to leads_path, :notice => 'Lead updated'
end
def destroy
Lead.delete(params[:id])
redirect_to leads_path, :notice => 'Lead deleted'
end
#protected
def load_collections
#lead_contacts = Lead.space_contacts
#sales_contacts = Lead.users
#statuses = Lead.statuses
end
end
-------------------------------------
- leads.rb file
class Lead < Podio::Item
APP_ID =12328033
SPACE_ID =3204114
# Find all items in the Leads app
def self.all
collection = self.find_all(APP_ID)
collection[:all]
end
# Find valid lead contacts in the space
def self.space_contacts
Podio::Contact.find_all_for_space(SPACE_ID, :order => 'contact', :limit => 12, :contact_type => 'space,connection', :exclude_self => false) rescue []
end
# Find valid sales contacts in the space
def self.users
Podio::Contact.find_all_for_space(SPACE_ID, :order => 'contact', :limit => 12, :contact_type => 'user', :exclude_self => false) rescue []
end
# Find valid statuses
def self.statuses
app = Podio::Application.find(APP_ID)
field = app.fields.find { |field| field['external_id'] == 'status' }
field['config']['settings']['allowed_values']
end
def self.create_from_params(params)
# raise fields.inspect
self.create(APP_ID, { :fields => fields_from_params(params) })
end
def self.update_from_params(id, params)
self.update(id, { :fields => fields_from_params(params) })
end
#
# Map the field values return by the Podio API to simple getters
#
def organization
field_values_by_external_id('company-or-organisation', :simple => true)
end
def lead_contact
field_values_by_external_id('contacts', :simple => true).try(:[], 'name')
end
def sales_contact
field_values_by_external_id('sales-contact', :simple => true).try(:[], 'name')
end
def potential_revenue_value
field_values_by_external_id('potential-revenue').try(:first).try(:[], 'value').to_i
end
def potential_revenue_currency
field_values_by_external_id('potential-revenue').try(:first).try(:[], 'currency')
end
def probability
field_values_by_external_id('probability-of-sale', :simple => true)
end
def status
field_values_by_external_id('status', :simple => true)
end
def followup_at
field_values_by_external_id('next-follow-up').try(:first).try(:[], 'start').try(:to_datetime)
end
protected
def field_values_by_external_id(external_id, options = {})
if self.fields.present?
field = self.fields.find { |field| field['external_id'] == external_id }
if field
values = field['values']
if options[:simple]
values.first['value']
else
values
end
else
nil
end
else
nil
end
end
def self.fields_from_params(params)
{
'company-or-organisation' => params[:organization],
'contacts' => (params[:lead_contact].present? ? params[:lead_contact].to_i : nil),
'sales-contact' => (params[:sales_contact].present? ? params[:sales_contact].to_i : nil),
'potential-revenue' => { :value => params['potential_revenue_value'], :currency => params['potential_revenue_currency'] },
'probability-of-sale' => params[:probability].to_i,
'status' => params[:status],
'next-follow-up' => DateTime.new(params['followup_at(1i)'].to_i, params['followup_at(2i)'].to_i, params['followup_at(3i)'].to_i).to_s(:db)
}.delete_if { |k, v| v.nil? }
end
end
I have an exam starts_at field, and what I want to do is, if current date is 1 day or more before exam starts_at I want to redirect to somewhere else. And if current date is the same day as when the exam starts_at I want to redirect to the exam page....for now I just want to get the if statement correct, I will put the redirect later.
Here is my controller.
Student Session Controller
class StudentSessionsController < ApplicationController
before_action :set_student_session
before_filter :config_opentok, except: :update
before_action :try_authenticate_user!, except: :mobile
before_action :check_compatability, except: :mobile
def show
#session = #student_session.session
#session_id = #session.session_id
#token = #opentok.generate_token #session_id, :data => "#{#student_session.id}"
# If Time.now is 1 or more days before exam starts_at show message
if (#session.exam.starts_at =< Time.now)
render :text => "OK"
else
render :text => "Not ok"
end
if #student_session.student.present?
#UserMailer.mobile_link(current_user.email, current_user.name, #student_session).deliver
else
#UserMailer.mobile_link(#student_session.email, #student_session.email, #student_session).deliver
end
ua = UserAgent.parse(request.user_agent)
#student_session.operating_system = ua.os
#student_session.browser = ua.browser
#student_session.browser_version = ua.version.to_s
#student_session.save
render layout: "application_no_header"
end
def mobile
#session = #student_session.session
#session_id = #session.session_id
#token = #opentok.generate_token #session_id, :data => "#{#student_session.id}_mobile"
render layout: false
end
def update
respond_to do |format|
if #student_session.update(student_session_params)
format.js
end
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_student_session
#student_session = StudentSession.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def student_session_params
params.require(:student_session).permit(:session_status, :publisher_status, :proctor_status, :mobile_status)
end
def config_opentok
#opentok ||= OpenTok::OpenTok.new APP_CONFIG['opentok']['api_key'], APP_CONFIG['opentok']['secret']
end
def try_authenticate_user!
if #student_session.student.present?
authenticate_user!
end
end
def check_compatability
user_agent = UserAgent.parse(request.user_agent)
# http://tokbox.com/opentok/requirements/
unless (user_agent.browser == 'Chrome' and user_agent.version.to_a.first >= 23) or
(user_agent.browser == 'Firefox' and user_agent.version.to_a.first >= 22)
redirect_to '/browser'
end
end
end
I'd suggest you use:
if #session.exam.starts_at.to_date == Date.today
# go to exam
elsif #session.exam.starts_at.to_date < Date.today
# go to place before the exam
else
# go to place after the exam
end
As you're using rails you can do
if (Time.now >= (#session.exam.starts_at - 1.day) )
render :text => "OK"
else
render :text => "Not ok"
end
if ((#session.exam.starts_at - Time.now).to_i / 1.day) >= 1
render :text => "OK"
else
render :text => "Not ok"
end