I have a rails site and I would like to render the live site through the dashboard. I have created a dashboard for the back end of the website but when a user makes a change I would like them to see it first.
Here’s my
Dashboard.rb
has_many :profiles, :dependent => :destroy
has_many :blogs, :through => :profile, :dependent => :destroy
has_many :videos, :through => :profile, :dependent => :destroy
has_many :albums, :through => :profile, :dependent => :destroy
Dashboard index.html
<%= render :partial => 'profiles/profile', :locals => {:profile => @profile} %>
Profile.rb
belongs_to :dashboard
has_many :blogs, :dependent => :destroy
has_many :videos, :dependent => :destroy
has_many :albums, :dependent => :destroy
_profile.html.erb
<h1><%= @profile.name %></h1>
<% album = @profile.albums.last %>
<% if album.blank? %>
<%= link_to 'Create a new album', new_album_path %></br>
<% else %>
<%= render :partial => 'albums/album', :locals => {:album => @profile.albums.last} %>
<% end %>
<% blog = @profile.blogs.last %>
<% if blog.blank? %>
<%= link_to 'Create a blog post', new_blog_path %><br/>
<% else %>
<%= render :partial => 'blogs/blog', :locals => {:blog => @profile.blogs.last}%>
<% end %>
<% video = @profile.videos.last %>
<% if video.blank? %>
<%= link_to 'Add new video', new_video_path %></br>
<% else %>
<%= render :partial => 'videos/video', :locals => {:video => @profile.videos.last} %>
<% end %>
The above works fine when I’m viewing the site through the frontend but when trying to view it through the dashboard I get the error
undefined method `name’ for nil:NilClass
Which is the profile.name line
If I delete the line above I get the
undefined method `shows’ for nil:NilClass
Anyone have any suggestions how I can solve this issue?
There needs to be
@profilefind inside controller. If the params id is not valid then it will redirect to root url and if valid it will render page.