Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 2.79 KB | None | 0 0
  1. module ApplicationHelper
  2.  
  3.   def is_a_number?(s)
  4.   s.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
  5. end
  6. end
  7.  
  8. require "application_helper"
  9.  
  10. class TipsController < ApplicationController
  11.  
  12.   # GET /tips
  13.   # GET /tips.xml
  14.   def index
  15.     @tips = Tip.all
  16.  
  17.     respond_to do |format|
  18.       format.html # index.html.erb
  19.       format.xml  { render :xml => @tips }
  20.     end
  21.   end
  22.  
  23.   # GET /tips/1
  24.   # GET /tips/1.xml
  25.   def show
  26.     @tip = Tip.find(params[:id])
  27.  
  28.     respond_to do |format|
  29.       format.html # show.html.erb
  30.       format.xml  { render :xml => @tip }
  31.     end
  32.   end
  33.  
  34.   # GET /tips/new
  35.   # GET /tips/new.xml
  36.   def new
  37.     @tip = Tip.new
  38.  
  39.     respond_to do |format|
  40.       format.html # new.html.erb
  41.       format.xml  { render :xml => @tip }
  42.     end
  43.   end
  44.  
  45.   # GET /tips/1/edit
  46.   def edit
  47.     @tip = Tip.find(params[:id])
  48.   end
  49.  
  50.   # POST /tips
  51.   # POST /tips.xml
  52.   def create
  53. ##here is where the things goes wrong
  54.     if is_a_number?("5")
  55.       puts "is number"
  56.     end
  57.     params[:tip][:tiptags_attributes][:"0"][:tags_id]=1
  58.     params.each() {|v,k| puts " v #{v} v class #{v.class}   k #{k} k class #{k.class}"  }
  59.     @tip = Tip.new(params[:tip])
  60.    
  61.    
  62.     #puts @tip.each(|v,k| puts v)
  63.    
  64.     puts "Printing @tip[:tiptags_attributes] "
  65.     @tiptag =params[:tip][:tiptags_attributes]
  66.     #puts @tiptag.attribute_names
  67.     puts params[:tip][:tiptags_attributes].each {|v,k| puts " v #{v} v class #{v.class}   k #{k} k class #{k.class}"  }
  68.     puts params[:tip][:tiptags_attributes][:"0"][:tags_id]
  69.    
  70.     puts params[:tip][:tiptags_attributes]
  71.     puts @tip.attribute_names
  72.    
  73.     puts @tip[:tiptags_attributes]
  74.     @tip[:tip]="cambiado"
  75.     puts @tip[:tip]
  76.    
  77.     respond_to do |format|
  78.       if @tip.save
  79.         format.html { redirect_to(@tip, :notice => 'Tip was successfully created.') }
  80.         format.xml  { render :xml => @tip, :status => :created, :location => @tip }
  81.       else
  82.         format.html { render :action => "new" }
  83.         format.xml  { render :xml => @tip.errors, :status => :unprocessable_entity }
  84.       end
  85.     end
  86.   end
  87.  
  88.   # PUT /tips/1
  89.   # PUT /tips/1.xml
  90.   def update
  91.     @tip = Tip.find(params[:id])
  92.  
  93.     respond_to do |format|
  94.       if @tip.update_attributes(params[:tip])
  95.         format.html { redirect_to(@tip, :notice => 'Tip was successfully updated.') }
  96.         format.xml  { head :ok }
  97.       else
  98.         format.html { render :action => "edit" }
  99.         format.xml  { render :xml => @tip.errors, :status => :unprocessable_entity }
  100.       end
  101.     end
  102.   end
  103.  
  104.   # DELETE /tips/1
  105.   # DELETE /tips/1.xml
  106.   def destroy
  107.     @tip = Tip.find(params[:id])
  108.     @tip.destroy
  109.  
  110.     respond_to do |format|
  111.       format.html { redirect_to(tips_url) }
  112.       format.xml  { head :ok }
  113.     end
  114.   end
  115. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement