I want to find a good way before looking at my object so that I do not get errors.
This is my controller
@user = User.find_by_username (params [: username]) @profile = @ user.profile @questions = @ user.questions
and this is my view
& lt;% unless there is no @ profile. Blanc? % & Gt; & Lt;% = link_to 'Edit Profile' ,: Controller = & gt; 'Profile',: Action => 'Edit'% & gt; & Lt;% end% & gt; & Lt;% as long as @ user.blank? & Gt%; Username: & lt;% = @ User Name %% & gt; & Lt; Br / & gt; Since members: & lt;% = @ user.created_at.strftime ("% d% B% Y")%> & Lt; Br / & gt; & Lt;% end% & gt; & Lt;% Not until @ Profile. Blanc? & Gt%; First name: & lt;% = @ profile.first_name% & gt; & Lt; Br / & gt; Last name: & lt;% = @ profile. last_name% & gt; & Lt; Br / & gt; & Lt; Br / & gt; About: & lt;% = @ profile.body% & gt; & Lt; Br / & gt; & Lt; Br / & gt; Location: & lt;% = @ Profile.Office% & gt; & Lt; Br / & gt; Birthday: & lt;% = @ Profile. Birthday. Shelter ("% d% B% Y")% & gt; & Lt; Br / & gt; & Lt;% end% & gt;
As you can see, I'm using more than one type of investigation of each type (unless it's @ profile.blank?) And I do not check that There will be a better way of doing this. / P>
Is any train clever with the way it has come with me?
As I have seen, there is no way that you can leave it @. Blanc? Verification If you are empty then do not want to display the record, but I have some suggestions
1 - Make the following sections partially
& Lt; Br / & gt; & Lt;% end% & gt;
and
& lt;% unless there is no @ profile. Blanc? & Gt%; First name: & lt;% = @ profile.first_name% & gt; & Lt; Br / & gt; Last name: & lt;% = @ profile. last_name% & gt; & Lt; Br / & gt; & Lt; Br / & gt; About: & lt;% = @ profile.body% & gt; & Lt; Br / & gt; & Lt; Br / & gt; Location: & lt;% = @ Profile.Office% & gt; & Lt; Br / & gt; Birthday: & lt;% = @ Profile. Birthday. Shelter ("% d% B% Y")% & gt; & Lt; Br / & gt; & Lt;% end% & gt;
This will keep your view cleaner and will give you flexibility to use any type of app in your app
2 - Take the bottom line
< Pre> & lt;% unless there is a @ Profile. Blanc? % & Gt; & Lt;% = link_to 'Edit Profile' ,: Controller = & gt; 'Profile',: Action => 'Edit'% & gt; & Lt;% end% & gt; The incision
Equality
Comments
Post a Comment