Skip to main content

Posts

Showing posts with the label Ruby on Rails

Load value to dropdown from table in Ruby on Rails

Its very simple to load the table value to dropdown box in ruby on rails.        Syntax :                  select(:model, :attribute, rails query) Example :       Now you need to load the countries table table to drop down mean                         select(:Country, :cname, Country.all.collect {|c| [ c.name, c.id ] })     Country => Its model name     cname  => Field name     Country.all  => Its load the all values to dropdown.     Its like "SELECT *FROM COUNTRIES"

Simple Image and File Upload using Ruby on Rails (CarrierWave gem)

I’m going to show you a very simple way to upload your attachments or a picture using CarrierWave gem. Steps: 1.    Open Terminal. 2.   Create a new project terminal > rails new imageupload 3.   Add this line to Gemfile     gem ‘ carrierwave ‘ 4.   terminal > bundle install 5.   terminal > rails g uploader image 6.   terminal > rails g scaffold Painting name:string image:string 7.   terminal > rake db:migrate 8.   Add this line to painting.rb (app/models/painting.rb)     class Painting < ActiveRecord::Base      mount_uploader :image, ImageUploader     end 9.   And then in your app/views/paintings/_form.html.erb edit your code, which become     <%= f.label :image %>     <%= f. text_field :image %>   ...