Another quick post, just on how to truncate a string within a view. I used the following in order to ensure that my order_item title is never longer than 100 characters:
Title: 100, :seperator => ' ...') %>
Output:
Title: lentesque porttitor
#More than 100 characters
Title: lentesque porttitor, velit vel ullamcorper pharetra, augue erat pharetra risus, quis bibendum fel…
Good Luck!
Adding a Link Within a Flash Notice/Message – Ruby on Rails
flash[:notice] = "Order created - Click here to pay for it!"
flash[:notice] = "Order created - Click here to pay for it!".html_safe
If you’re using rails 3 make sure you throw in the .html_safe or your link will be appear as plain text. Just a quick screenshot of the end result below:
Anyway, that’s all. Good Luck!
Passing Variables to a Partial from a View – Ruby on Rails
Just another one of those things that I find myself needing to do from time to time. Luckily this is all pretty straight forward (thankyou Ruby on Rails!). Assuming your partial is a form in the locations folder and that the variable you’re expecting is location all that you have to do is following:
View: users/show.html.erb
'locations/form', :locals => { :location => @user.location } %>
Partial: locations/_form.html.erb
Street:
Good luck!
Error 324 (net::ERR_EMPTY_RESPONSE) – Ruby on Rails
Unable to load the webpage because the server sent no data.
Here are some suggestions:
Reload this webpage later.
Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.
This wasn’t one I had encountered before and unfortunately Google couldn’t give me anything to cheat off. Luckily, a quick review of the server log revealed the following message just before it closed the connection:
#Redirect to edit location path redirect_to '/locations/edit'
Hopefully this’ll be able to help someone else out there, Good Luck!
Custom Form Submit Button Text – Ruby on Rails
Good Luck!
Validation Error Messages not Displaying – Ruby on Rails
— Usually an error would appear here —
Turns out the problem was pretty straight forward – it’s always the little things! I’d simply missed the each when displaying the error messages:
prohibited this message from being saved:
-
Country can’t be blank
Good Luck!