Skip to content

Instantly share code, notes, and snippets.

question controller
def create
Question.create(params[:question]);
end
question new view
1 <h1>Question Form</h1>
2
3 <%= form_for @question, url: {action: "create"} do |f| %>
def create
33 Question.create(question_params);
34 # Question.create(:title => params[:question][:title],
35 # :summary => params[:question][:summary],
36 # :subject_id => params[:question][:subject])
37 end
38 def question_params
39 params.require(:question).permit(:title,:summary,:subject_id)
40 end
controller
def create
32 params[:question][:subjects].delete_if { |n| n == "" }
33 Question.create(:title => params[:question][:title],
34 :summary => params[:question][:summary],
35 :subject_id => params[:question][:subjects])
36 end
model
1 class Question < ActiveRecord::Base
Subject.joins(:questions).where(:questions => {:id => 3}) // to search questionS_subjects join table for triedto
1 class OffersController < ApplicationController
2 before_action :authorize_user
3 def show
4 @validOffer = Offer.exists?(params[:id]);
5 puts @validOffer
6 if @validOffer
7 @offers = Offer.where(:question_id => params[:question_id]);
8 else
9 redirect_to root_path
10 end
@bmax
bmax / emberhelp
Last active August 29, 2015 14:05
routers.js
---
import Ember from 'ember';
var Router = Ember.Router.extend({
location: GrowlogWebENV.locationType
});
Router.map(function() {
this.route('login');
app/index.html
---
app/initiliazers/application.js
---
import Ember from 'ember';
import Base from 'simple-auth/authenticators/base';
var CustomAuthenticator = Base.extend({
{{#if showForm}}
{{input id='operation_name' placeholder='Operation Name' value=operation_name}}
<button {{action 'submitOp'}}>Add Operation</button>
<button {{action 'hide'}}>Hide</button>
{{else}}
<button {{action 'show'}}>Add operation</button>
{{/if}}
{{#if showRoomForm}}
Hello
{{/if}}
@bmax
bmax / application.js
Created August 28, 2014 17:50
Changing buildURL according to the record type.
createRecord: function(store, type, record) {
var data = {};
var serializer = store.serializerFor(type.typeKey);
serializer.serializeIntoHash(data, type, record, { includeId: true });
if (record.get('isNew') && type.typeKey == 'room' && data.room.operation_id)
{
var op_id = data.room.operation_id;
delete data.room.operation_id;
return this.ajax(this.buildURL('operations/' + op_id + '/room', null, record), "POST", { data: data });
import Ember from 'ember';
export
default Ember.View.extend({
templateName: 'driver',
didInsertElement: function() {
this._super();
var chart = c3.generate({
bindto: '#chart',
data: {