Hey everyone,
So I'm new to Rails (teaching myself as a senior project in high school), and I'm trying to figure out how to modify these strings.
Let's say someone writes the following string in a form: "you know you are a geek when"
How can I automatically change it to this: "You know you are a geek when..."?
I need Rails to check the case of the first letter and check for the three dots then modify the string as necessary. I've looked here, but I can't find anything that would work.
Thanks a lot!
EDIT: I'm trying to implement what Reuben Mallaby suggested, but I'm having trouble. Here's the relevant part of the lists_controller.rb file, and below that is the method in the list.rb model.
def update
@list = List.find(params[:id])
@list.fixlistname
respond_to do |format|
if @list.update_attributes(params[:list])
flash[:notice] = 'List was successfully updated.'
format.html { redirect_to(@list) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @list.errors, :status => :unprocessable_entity }
end
end
end
and..
def fixlistname
new_title = title.humanize + (title.ends_with("...") ? "" : "...")
end
EDIT 2: I want the string to be modified before it goes into the database, and this is the error message I'm getting:
undefined method `ends_with' for "You know you are a track runner when":String
GOT IT WORKING! THANKS EVERYONE!