Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module ApplicationHelper
- def is_a_number?(s)
- s.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
- end
- end
- require "application_helper"
- class TipsController < ApplicationController
- # GET /tips
- # GET /tips.xml
- def index
- @tips = Tip.all
- respond_to do |format|
- format.html # index.html.erb
- format.xml { render :xml => @tips }
- end
- end
- # GET /tips/1
- # GET /tips/1.xml
- def show
- @tip = Tip.find(params[:id])
- respond_to do |format|
- format.html # show.html.erb
- format.xml { render :xml => @tip }
- end
- end
- # GET /tips/new
- # GET /tips/new.xml
- def new
- @tip = Tip.new
- respond_to do |format|
- format.html # new.html.erb
- format.xml { render :xml => @tip }
- end
- end
- # GET /tips/1/edit
- def edit
- @tip = Tip.find(params[:id])
- end
- # POST /tips
- # POST /tips.xml
- def create
- ##here is where the things goes wrong
- if is_a_number?("5")
- puts "is number"
- end
- params[:tip][:tiptags_attributes][:"0"][:tags_id]=1
- params.each() {|v,k| puts " v #{v} v class #{v.class} k #{k} k class #{k.class}" }
- @tip = Tip.new(params[:tip])
- #puts @tip.each(|v,k| puts v)
- puts "Printing @tip[:tiptags_attributes] "
- @tiptag =params[:tip][:tiptags_attributes]
- #puts @tiptag.attribute_names
- puts params[:tip][:tiptags_attributes].each {|v,k| puts " v #{v} v class #{v.class} k #{k} k class #{k.class}" }
- puts params[:tip][:tiptags_attributes][:"0"][:tags_id]
- puts params[:tip][:tiptags_attributes]
- puts @tip.attribute_names
- puts @tip[:tiptags_attributes]
- @tip[:tip]="cambiado"
- puts @tip[:tip]
- respond_to do |format|
- if @tip.save
- format.html { redirect_to(@tip, :notice => 'Tip was successfully created.') }
- format.xml { render :xml => @tip, :status => :created, :location => @tip }
- else
- format.html { render :action => "new" }
- format.xml { render :xml => @tip.errors, :status => :unprocessable_entity }
- end
- end
- end
- # PUT /tips/1
- # PUT /tips/1.xml
- def update
- @tip = Tip.find(params[:id])
- respond_to do |format|
- if @tip.update_attributes(params[:tip])
- format.html { redirect_to(@tip, :notice => 'Tip was successfully updated.') }
- format.xml { head :ok }
- else
- format.html { render :action => "edit" }
- format.xml { render :xml => @tip.errors, :status => :unprocessable_entity }
- end
- end
- end
- # DELETE /tips/1
- # DELETE /tips/1.xml
- def destroy
- @tip = Tip.find(params[:id])
- @tip.destroy
- respond_to do |format|
- format.html { redirect_to(tips_url) }
- format.xml { head :ok }
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement