create new project
rails new NewRORProject
cd NewRORProject
generate model , view , controller for posts table
rails generate scaffold Post name:string title:string content:text
create new project
rails new NewRORProject
cd NewRORProject
generate model , view , controller for posts table
rails generate scaffold Post name:string title:string content:text
in controller
layout 'application', :except => :view
OR
in action
def view
...
render :layout => false
end
to disable one function
add this at the end of function
respond_to do |format|
format.html { render :layout => false } # your-action.html.erb
end
== to disable layout for all controller functions
add this to the top of controller file
layout false
yum install ruby
install Ruby dependancies.
yum install gcc g++ make automake autoconf curl-devel openssl-devel zlib-devel httpd-devel apr-devel apr-util-devel sqlite-devel yum install ruby-rdoc ruby-devel
yum install rubygems
gem update
gem update --system
then install rails
gem install rails
for check version try
gem install rails -V
to view the belong to as select option in add or edit view
use this the new edit view page
<%= f.select :category_id, Category.all.collect {|p| [ p.name, p.id ] } %>
add
category_id column to posts table
rails g migration add_category_id_to_posts category_id:integer
You ought to edit automatically generated migration and add line on the end of change
method:
add_index :posts, :category_id
then run : rake db:migrate
----------------------------
if there is aproblem in saving new fields to database
you must permit it in the controller
like this
def user_posts_params
params.require(:user_posts).permit(:user_id, :category_id
)
end
and this in the model
attr_accessible :user_id, :category_id